×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

SW API CreateLine2 function

SW API CreateLine2 function

SW API CreateLine2 function

(OP)
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!

RE: SW API CreateLine2 function

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

RE: SW API CreateLine2 function

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.

RE: SW API CreateLine2 function

(OP)
CreateLine doesn't show up in the module references...maybe it was pulled from the object library.

RE: SW API CreateLine2 function

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.

RE: SW API CreateLine2 function

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

RE: SW API CreateLine2 function

From API help for 2001+

Quote:

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

RE: SW API CreateLine2 function

(OP)
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"!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources