AnsweredAssumed Answered

macro sketchmanager draws wrong lines with correct values

Question asked by Eugen Fritz on Jun 30, 2017
Latest reply on Jul 3, 2017 by Greg James


I currently write a macro which should automatically draw lines in a sketch with a loop. At first the macro reads certain cells from an excel file. These cells are written in an array value1 ( 0 to 9999).


My problem is, when the macro starts to draw the lines, the first line has the length of maybe 10cm, these values came from my array for length value1(0). It draws a line with 10 cm.

The second line should have the length of 20 cm, this is the second point in my array value1(1).  But the macro is not drawing the second line with the length of 20 cm. Instead it draws a second line with a length of 10cm like the first position in my array. The loop counts the correct  values from my array higher and higher but it doesn’t take over the right values to the Solidworks Sketchmanager.

Sorry for my English.


Code for excel to read the cells.


Dim Typ1 As Variant                 'Zellen Fenster Typ1

For Each Typ1 In Range("G33:G155")

  If Typ1 <> "" Then

    value1(i) = Typ1

    i = i + 1

    j = i

  End If




Dim Abun As Variant                 'Zellen Fenster Typ1

For Each Abun In Range("F33:F155")

  If Abun <> "" Then

    value5(Y) = Abun

   Y = Y + 1

  End If



loop to draw the lines:

i = 0

For i = 0 To j

Set skSegment = Part.SketchManager.CreateCenterLine((value1(i) / 2000) * -1, value5(i) / 1000, 0#, value1(i) / 2000, value5(i) / 1000, 0#)

Next i


Maybe it is easier with Pictures.


The first picture (Picture1.1) shows my part how it should be with a correct sketch and the associated excel document.


The picture2.1 shows what my macro unfortunately is doing.


In the Picture3.1 you can see that the values I need are the correct ones. 26.1,28,31,34…….


Sometimes the code draws the correct length of lines, but mostly not.


You can try with the excel document in the attachment. There are 3 kinds of “windows”  picture5.1/7.1/8.1 but the problem only occurs in picture5.1 and picture7.1 also not always.


My last problem is, when the distance between two lines with different lengths and different highs are low, meassured from the coordinate system,  the system sets the same dimension to both lines, and the dimension is also set by the macro.

You can see this problem in the picture6.1 actually there are two lines, a line with a high 15,8mm from the coordinate system and a length with 77,8mm and a second line with a high 16,4mm and a length with 78,8mm. The macro draws two lines with the same high and length but it should be two different lines.


I hope you understand my problem and can give me a solution or an advise.


kind regards


Eugen Fritz