SW API Question: bug when drawing lines, etc w/ macros
SW API Question: bug when drawing lines, etc w/ macros
(OP)
I have a question about SolidWorks API, dealing with using VB & Macros to draw lines in model sketches and drawing views...
If you have the display at "Zoom All" and you use a program to start drawing lines that are close together, the lines seem like they are using the sketch relation tools and 'snapping' together...
For example, if you are using a D Size drawing and make to equal parallel lines, side by side, .05 apart... the second will be drawn on top of the first (w/ coincident points) in stead of actually being .05 apart...
BUT if you Zoom In, then draw them, they are drawn correctly...
I am making a log-log grid using a program to automate the drawing of aprox. 130 vertical lines and 100 horizontal lines...
the lines are draw using...
'set up the extents...
X1 = Log(1)
Y1 = Log(500)
X2 = Log(150)
Y2 = Log(15000)
'set up the max extents in log() format... with origin at 0,0
maxX = X2 - X1
maxY = Y2 - Y1
'vertical line
Dline Log(X) - X1, 0, Log(X) - X1, maxY
'horizontal line
Dline 0, Log(Y) - Y1, maxY, Log(Y) - Y1
Sub DLine(a1 As Double, b1 As Double, a2 As Double, b2 As Double)
'Create a line on the active Sketch/Drawing View
'Part.CreateLineVB X1, Y1, Z1, X2, Y2, Z2
Part.CreateLineVB CM(a1), CM(b1), 0, CM(a2), CM(b2), 0
End Sub
'Convert to Metric (inches to meters for SW)
Function CM(X As Double) As Double
CM = X * 0.0254
End Function
*Note: in my program I use Option Explicit, and all coord values are Double, counters are Integer or Long... And I use multiple For:Next loops to draw the Grid at different intervals when the Grid lines start to get too close togeter...
Anyways, Like I said above...
The problem is that when the end points get to close together, using the viewable distance, they create coincident relationships causing multiple lines to be drawn on top of each other, rather than the way they are suposed to be draw...
The only fix I have found is to Zoom in up close and then draw the lines and then zoom back out to ALL...
Part.ViewZoomTo2 -0.0003, 0.0002, 2.82573E-16, 0.0006, -0.0003, 3.28574E-16
...
'Draw Lines
...
Part.ViewZoomtofit2
Now I am assuming it is doing this because automatic relationships are turned on...
Normally I want this to be turned on when I am manually sketching...
Is there a way to Programatically disable the auto-relationships while drawing the lines, in place of the zoom comands, the restore the settings when done drawing?
-OR-
Is there a different way (API command) to draw the lines that do not use the system settings (like Auto Relationships) to draw the lines, and actually draw them to the EXACT X,Y coords you specify???
I know this might be a little confusing, It is kind of hard to explain with words...
Any help/suggestions will be appriciated...
If you need me to give further explaination, please let me know...
If you have the display at "Zoom All" and you use a program to start drawing lines that are close together, the lines seem like they are using the sketch relation tools and 'snapping' together...
For example, if you are using a D Size drawing and make to equal parallel lines, side by side, .05 apart... the second will be drawn on top of the first (w/ coincident points) in stead of actually being .05 apart...
BUT if you Zoom In, then draw them, they are drawn correctly...
I am making a log-log grid using a program to automate the drawing of aprox. 130 vertical lines and 100 horizontal lines...
the lines are draw using...
'set up the extents...
X1 = Log(1)
Y1 = Log(500)
X2 = Log(150)
Y2 = Log(15000)
'set up the max extents in log() format... with origin at 0,0
maxX = X2 - X1
maxY = Y2 - Y1
'vertical line
Dline Log(X) - X1, 0, Log(X) - X1, maxY
'horizontal line
Dline 0, Log(Y) - Y1, maxY, Log(Y) - Y1
Sub DLine(a1 As Double, b1 As Double, a2 As Double, b2 As Double)
'Create a line on the active Sketch/Drawing View
'Part.CreateLineVB X1, Y1, Z1, X2, Y2, Z2
Part.CreateLineVB CM(a1), CM(b1), 0, CM(a2), CM(b2), 0
End Sub
'Convert to Metric (inches to meters for SW)
Function CM(X As Double) As Double
CM = X * 0.0254
End Function
*Note: in my program I use Option Explicit, and all coord values are Double, counters are Integer or Long... And I use multiple For:Next loops to draw the Grid at different intervals when the Grid lines start to get too close togeter...
Anyways, Like I said above...
The problem is that when the end points get to close together, using the viewable distance, they create coincident relationships causing multiple lines to be drawn on top of each other, rather than the way they are suposed to be draw...
The only fix I have found is to Zoom in up close and then draw the lines and then zoom back out to ALL...
Part.ViewZoomTo2 -0.0003, 0.0002, 2.82573E-16, 0.0006, -0.0003, 3.28574E-16
...
'Draw Lines
...
Part.ViewZoomtofit2
Now I am assuming it is doing this because automatic relationships are turned on...
Normally I want this to be turned on when I am manually sketching...
Is there a way to Programatically disable the auto-relationships while drawing the lines, in place of the zoom comands, the restore the settings when done drawing?
-OR-
Is there a different way (API command) to draw the lines that do not use the system settings (like Auto Relationships) to draw the lines, and actually draw them to the EXACT X,Y coords you specify???
I know this might be a little confusing, It is kind of hard to explain with words...
Any help/suggestions will be appriciated...
If you need me to give further explaination, please let me know...






RE: SW API Question: bug when drawing lines, etc w/ macros
One thing that helped was turning off auto-relations. I did this from inside the code, and had a marker so that the program would return that setting to what it was before.
Look up SetUserPreferenceToggle in the API SolidWorks help.
RE: SW API Question: bug when drawing lines, etc w/ macros
'toggle off
swApp.SetUserPreferenceToggle swSketchAutomaticRelations, False
...
'sketch lines
...
'toggle back on
swApp.SetUserPreferenceToggle swSketchAutomaticRelations, True
Thanks Alot,
I thought I had seen it somewhere before...
Have a start for the quick response...
Thanks,
--Josh--
RE: SW API Question: bug when drawing lines, etc w/ macros
Well, that worked for the relationships... BUT...
The problem seems to be caused by those dashed horizontal/vertical lines that extend from the endpoint of lines, ect... when your cursor is in-line with them...
And cause the End/Start point to snap to be in line with the point, horizontally or vertically...
I can't find anywhere in the options to turn this off...
Is it possible to turn it off?
RE: SW API Question: bug when drawing lines, etc w/ macros
When I sketch, I usually draww line deliberately skewed to avoid horizontal & vertical snaps and constraints.
Maybe this could work in your program. First draw the lines skewed and then move the endpoints.
RE: SW API Question: bug when drawing lines, etc w/ macros
Tools>Sketch Settings...>Automatic Inferring Lines
I recorded a macro, and the vb command seems to be...
Part.AutoInferToggle
***Note: this option is Sketch Specific...
It must be turned on/off on each individual sketch...
And is NOT a system option...
RE: SW API Question: bug when drawing lines, etc w/ macros
Is that each sketch or each part?
Regg
RE: SW API Question: bug when drawing lines, etc w/ macros
within a part, it is possible for 1 sketch to have the option enabled and another to have it disabled...
-Josh
RE: SW API Question: bug when drawing lines, etc w/ macros
'(Assuming Part is a ModelDoc)
Sub DLine(a1 As Double, b1 As Double, a2 As Double, b2 As Double)
'Create a line on the active Sketch/Drawing View
'Part.CreateLineVB X1, Y1, Z1, X2, Y2, Z2
Part.SetAddToDB = True
Part.CreateLineVB CM(a1), CM(b1), 0, CM(a2), CM(b2), 0
Part.SetAddToDB = False
End Sub
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
RE: SW API Question: bug when drawing lines, etc w/ macros
That works great...
BUT...
Part.SetAddToDB = True
...
Part.SetAddToDB = False
Needs to be...
Part.SetAddToDB True
...
Part.SetAddToDB False
the definition is:
void ModelDoc2.SetAddToDB ( setting)
Input:
(BOOL) setting
TRUE if you want items added directly to the SolidWorks database, FALSE otherwise.
Thanks DSI, have a star...
-Josh
RE: SW API Question: bug when drawing lines, etc w/ macros
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.