API Help! TRAK CNC programming from SW

Well, I've taken Corey's advice and dove into writing a macro to program our 2-axis CNC mill from SolidWorks. Theoretically, the process is simple (select line and arc endpoints, and arc centerpoints, get coordinates, and format into text the CNC mill can read). But, there are a few VBA / API roadblocks I've run into after about a day working on it. Here is the macro:

formatting link
Current Problems:

-The macro won't run except from the VBA Editor (with "sub main()" selected and the "play" button)

-I can't figure out a way to select more points / arcs as the macro goes on... only pre-selection is obvious.

Any tips? Ideally, I'd like my userform to pop up, and prompt the user to select vertices and centerpoints while choosing userform options in between. Is this possible? Manipulating focus between my userform and the solidworks graphics window seems difficult.

Oh, and if you can't tell, I'm an amateur at VBA. Also, I'm running SW Student Edition 2004-2005 on Windows 2000.

Thanks for any help you can give! Denny Trimble University of Washington

Reply to
Denny Trimble
Loading thread data ...

To run from the play button Sub Main has to be the last sub in it's module. You could also run it from a custom macro button and specify exactly which sub should run when the button is hit.

Use selection manager events and set modal to false

initialize_form InputForm.Show False 'false is telling sw that you want to interact with the model while the form stays in front.

to use events in the form module add this to the top

Public withevents ThisPart as sldworks.PartDoc

Private Function ThisPart _NewSelectionNotify() As Long 'this code will run every time a selection is changed. ProcessNewSelection

End Function

Private Sub UserForm_Initialize() 'this will start the watch on the active document Set ThisPart = SwApp.ActiveDoc

End Sub

My initial thought would have been to make a drawing view that is HLR and parse the lines and arcs in the view with maybe one selection point for the Machine Origin. You are already half way there and your way gives the user more control but also more clicks. Just trying to be objective.

Regards

Corey Scheich

the modal thing will take care of all this

Reply to
Corey Scheich

How about actually reading the geometry out of the drawing view(s) ? The more complicated the geometrie(s), the more work for the user...

heres a link that may help you get started...

formatting link
While I have/(had ?) code to read and 'sew' the flat pattern geometries into boundaries, this week, after a few years of using it, I *finally* ran into a Flat pattern that contained SPLINES and POLYLINES. So Im currently re-writing it now that I have some sample geometry to try it on....

Also, when reading 2D arcs in SWX, it always tries to output the travel per cartesian coordinate system (CCW), and even when this is counter to the actual arc, and it will just flip the arc NORMAL. Gotta be careful there.....

Reply to
rocheey

Thanks for the help Corey! I'll let you know how it goes when I have time to work on it some more.

I thought about selecting a loop and having the code take it from there, but I don't know how to control the direction and start point with that method. You're probably familiar with climb cutting vs. traditional cutting, for example aluminum requires climb cutting, so the tool should travel CCW on an inside profile and CW on an outside profile. I wanted to make sure I had control of this.

I'll also probably play around with making offset profiles for machining odd-shaped flat-bottom pockets. That's where the TRAK programming interface is really lacking.

Thanks again! I'll post an update here soon.

-Denny

Reply to
Denny Trimble

You have to locate the arc's center relative to it's start & end angle AND know where you are starting on it (which end) to know if you should be going CLW or CCLW. Note that where you are to start with may very well not be the first endpoint in the arc's data as stored in the part database. You have to check.

Arcs in many/most CAD or CAD/CAM part databases are stored in CCW format.

Then there's the issue of tool centerline programming vs. WSP (Work Surface Programming). In the former case you will need offset curves/tool paths.

Reply to
Cliff

I noticed that any public procedures without arguments can run before "main" (depending on the order they are in, in the module, I suppose. - Although if you have more than 1 module in your macro, that can get a little confusing.) To get rid of this problem, simply put arguments in all your procedures, whether you need them or not.

Reply to
What-a-Tool

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.