×
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 macro

SW macro

SW macro

(OP)
hi

I have made this macro to plot some points in a sketch, but depending on if there is zoomed out or in, it will plot it wrong or right.

Dim swApp As Object
Dim Part As Object
Dim SelMgr As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Feature As Object


Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc
Set SelMgr = Part.SelectionManager


A = 0.3
B = 0.3
X = 0
C = 0
Y = 0
K = 0.8

ST:
X = X + 0.1
Y = A * X ^ 2 + B * X ^ 2 + C
Part.CreatePoint2 X, Y, 0

If X < K Then GoTo ST

End Sub

RE: SW macro

What do you mean by "wrong or right"?  I can't get it to behave unexpectedly.  

By the way, what programming language are you used to?  Using GoTo to create a loop is generally considered poor programming practice in VB/VBA.

-handleman, CSWP (The new, easy test)

RE: SW macro

(OP)
then try to zoom out an run the macro again.

yes it is poor programming, but im also new to this ;O)

RE: SW macro

(OP)
remember to delete the old points before you run it again

RE: SW macro

I see what is happening.  When a point is created, SW looks to see where it is.  If your zoom level is such that SW thinks the points are right on top of each other, it won't add them.  Just like if you try to manually insert a point on top of an existing point.  You have to tell SW to ignore anything that might be near the point locations and just put them in.  You do that with SetAddToDB and SetDisplayWhenAdded.



CODE


Dim swApp As Object
Dim Part As SldWorks.ModelDoc2
Dim SelMgr As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Feature As Object


Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc
Set SelMgr = Part.SelectionManager
Part.SetAddToDB True
Part.SetDisplayWhenAdded False

A = 0.3
B = 0.3
X = 0
C = 0
Y = 0
K = 0.8

ST:
X = X + 0.1
Y = A * X ^ 2 + B * X ^ 2 + C
Part.CreatePoint2 X, Y, 0

If X < K Then GoTo ST
Part.SetAddToDB False
Part.SetDisplayWhenAdded True
End Sub

-handleman, CSWP (The new, easy test)

RE: SW macro

(OP)
Thanks - now I see it works fine. My firm don´t have anything about makking macros in sw. Do SW offer any books/documentation on how to make marcos ?

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