Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

SW API CreateLine2 function 1

Status
Not open for further replies.

alexit

Mechanical
Dec 19, 2003
348
I am using the following snippet of code to plot point data from a bit of calculation software. These points are not described by an equation, and because the points are very close together SW will not create a spline through them. Dropping every N points doesn't work as they are not very predicatable and the spline misrepresents the points badly.

Unfortunately I am finding the CreateLine2 function is extremely slow, about 2 second each little line, or over an hour total. Anyone have a suggestion to improve the speed?

Val = swModel.GetUserPreferenceToggle(swInputDimValOnCreate)
swApp.SetUserPreferenceToggle swInputDimValOnCreate, False
swModel.InsertSketch2 True
swModel.ClearSelection2 True
swModel.CreateCircleByRadius2 0, 0, 0, (ID / 2)
swModel.AddDiameterDimension2 (ID / 2), (ID / 2), 0
swModel.CreateCircleByRadius2 0, 0, 0, (OD / 2)
swModel.AddDiameterDimension2 (OD / 2), (OD / 2), 0
swApp.SetUserPreferenceToggle swInputDimValOnCreate, Val
swModel.InsertSketch2 True
swModel.ClearSelection2 True
For i = 1 To j - 1
p1x = points(1, i) * 0.0254
p2x = points(1, i + 1) * 0.0254
p1y = points(2, i) * 0.0254
p2y = points(2, i + 1) * 0.0254
swModel.CreateLine2 p1x, p1y, 0, p2x, p2y, 0
Next i


Thanks for all your help!
 
Replies continue below

Recommended for you

I too have seen the slow drawing of lines with the API. It only seems to be with the CreateLine2 in SW2006. Before that, with SW2004 the macro just flew thru drawing the lines.

Sorry I can't suggest any work-arounds.

Ken
 
Have you tried using the obsoleted CreateLine version? It should be supported, although documentation may not be easy to find. As long as you can figure out how to get the arguments right it might be worth a shot to try.
 
CreateLine doesn't show up in the module references...maybe it was pulled from the object library.
 
I think none of the obsoleted objects etc show up, but I think most if not all are still supported if you can figure out the syntax. Of course, it may not be worth the trouble to try to figure it out. There's nothing saying that it'll work any faster.
 
You should be able to find the Obsoleted help page from the Search Tab in the SW API Help. Go to that tab and enter "CreateLine" at the Search Tab in the SW API Help. Works here,

Ken
 
From API help for 2001+

This function creates a line from P1 to P2. The CreateLineVB should only be used in Visual Basic and other forms of Basic which do not support SAFEARRAYS.CreateLine and CreateLineVB also enable automatic relations for the line which may not be suitable for creating very small segments in database.



Syntax (OLE Automation)



retval = ModelDoc2.CreateLine ( P1, P2)



Input:
(VARIANT) P1
VARIANT of type SAFEARRAY of 3 doubles(x1, y1, z1) in meters which describe the first point of the line

Input:
(VARIANT) P2
VARIANT of type SAFEARRAY of 3 doubles(x2, y2, z2) in meters which describe the second point of the line

Return:
(VARIANT_BOOL) retval
Only for CreateLine, TRUE if success, FALSE if fail

SA
 
Found it, when revised with this code the lines are inserted instantly:

swModel.SetAddToDB True
swModel.SetDisplayWhenAdded False
For i = 1 To j - 1
p1x = points(1, i) * 0.0254
p2x = points(1, i + 1) * 0.0254
p1y = points(2, i) * 0.0254
p2y = points(2, i + 1) * 0.0254
swModel.CreateLine2 p1x, p1y, 0, p2x, p2y, 0
Next i
swModel.SetDisplayWhenAdded True
swModel.SetAddToDB False

Thanks for all the replys, pointed me in the right place of the "help"!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor