AnsweredAssumed Answered

SW API: please help me to understand it

Question asked by Dmitry Dymov on May 29, 2020
Latest reply on Jun 1, 2020 by Dmitry Dymov

Hello everyone!

 

I'm new to 3D CAD in general, and SW in particular.

 

My (main) part is an intersection of many half-spaces, with many of the planes very specially oriented and positioned in space. The number of half-spaces is variable. That's why I'm trying to script it (VBA).

 

I find the API somewhat inconvenient, and some of its approaches don't make much sense to me. I'm struggling thru the API, not working with it. I'm hoping that if someone gives me some clues, links or explainations, it would be easier for me to accept the way SW API is and adapt to it.

 

  1. In examples I see that we first select objects with SelectByID2, then we call some function, like FeatureExtrusion3. I often had big problems selecting (taking hints from recorded macros, searching internet and studying online examples). Why not to return an ID/handle for objects that we create, and then pass this handle to select? After all, this is what the name implies, SelectByID2! (eventually I did what I wanted, but I'd call my solution -- a luckily found workaround)
  2. SelectByID2 often needs selection points, and I see them in examples as hard-coded "magic numbers". I calculate them myself in my script, but isn't it an inconvenience?
  3. Direction of extrusion (true/false) is often wrong. In the GUI it's a simple click, because you see everything. But in the script I can't visually adjust it. All the sketches (circles in my case) are created by same code, the only difference is in orientation of planes. Still, extrusion directions are different for different plane orientations. How one is supposed to script that?
  4. A very simple macro that is freshly (SW just started) recorded, doesn't produce same result when executed (also in a freshly restarted SW, to have naming same, like "Line1@3DSketch1"). Macro recording looks pretty useless then --- if you need to study examples anyway.

 

The API looks like it has simply been exposed from whatever SW GUI did many years ago. Without (much) re-design to make it convenient for programming.

 

I had no problems programming in VBA in MS Office (excel, access) many years ago, all made pretty good sense to me. Compared with that, SW API appears to me to be poorly suited for scripting. Am I right? (SW *GUI* looks wonderful, powerful and easy -- no doubts). Thanks.

Outcomes