Garren Hahn

Userform and Module declarations, public vs private, passing enities, and other questions.

Discussion created by Garren Hahn on Jun 9, 2020
Latest reply on Jun 10, 2020 by Garren Hahn



I'm working on a macro to generate some geometry for me. It's simple work to do manually for one inside corner, but I want to make a macro as I have potentially hundreds coming up to do in the same fashion. I am alsorather new at the VBA/API side of things and need the experience.


What I'm wanting to do is this:

  1. Create a plane that's mid plane to 1st Adjacent Face and 2nd Adjacent Face.
  2. Create 2 lines on that plane; 1 that starts at the Seam Top Vertex and the other at the Seam Bottom Vertex, make them parallel, and dimension them to the line(called seam above) using the value in the Tool Tip Angle field. The dimension should be acute towards the side above Top Seam Vertex. (see photo below)


Below is a form I have created to help me select and identify the entities. The desired result would be to have the buttons labeled 'Select Entity' populate the fields with the entity name but I also need to store the object for building off of later. So, my question here would be:

 - How should I handle the storing of this object on the click of  the 'Select Entity' button and access it's properties for use in other subs?


Another question I have is this: Should I publicly declare my instances of SldWorks, ModelDoc2, ModelDocExtension, etc. in just one module so I can access them in any module? I ask this because the Userform and everything associated with it seem to be in it's own module apart from the main module. I guess I'm asking what the best practice is for this.


Bonus question: What's the best method for incorporating another macro into this one? I had to create a macro to calculate the Tool Tip Angle that I have to input into this form. I had to make that macro because the math is calculated by the assembly I designed and the math equation itself is both way over me and I haven't been able to find a formula or a way to make a formula for it. What that macro does is it opens a doc, shows a form, user inputs values, and when you hit ok the global variables are updated and a final angle is given to me. It seems like I would have to incorporate that macro's entire code into this one as I'm not sure if there is a way to pass variables between macros.