SWVB101
Mechanical
- Jun 25, 2003
- 85
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...