1 Reply Latest reply on Nov 7, 2017 4:28 PM by John Alexander

    How to get LineStyle of selected edge in developing Macro?

    Ninad Kulkarni

      I  am trying to write a macro to create manufacturing instructions where I need to specify if the hole is on the front face or rear. My plan is to sort the selected holes using the type of line for the edge of the hole. Is there any existing macro for this problem? Any other approaches are also welcome!

        • Re: How to get LineStyle of selected edge in developing Macro?
          John Alexander

          I don't have a suggestion for getting the linetype from edges. I think there will be some pitfalls with this approach.

           

          If these are HoleWizard holes, is it possible for them to be tapped, counterbored, etc? Do you need to communicate hole type in your list? How will you get that from the drawing edges?

           

          I would suggest going to the source and looking at the HoleWizard Features themselves.

           

          1. For the drawing view in question, get the View's referenced ModelDoc. I'm not sure what the exact property name is but you should be able to find this in the API documentation.

           

          2. Loop over the feature tree; something like ModelDoc.GetFeatures(). For each feature, check if getTypeName2 returns "HoleWzd".

           

          3. For each HoleWizardFeature, use GetFaces to get an array of faces associated with that hole feature. For each Face, use getSurface to get the Surface (I think there should be only one for each face). For each Surface, check if it is cylindrical. for each cylindrical surface, get the CylinderParams

           

          2012 SOLIDWORKS API Help - ICylinderParams Property (ISurface)

           

          A subset of the cylinder params is the cylinder's axis vector {x,y,z}. You can use the data from that vector to create a MathVector.

           

          4. For each mathvector that you build, mulitply it by the drawing View's ModelToViewTransform. The result of that transformation should equal {0,0,1} or {0,0,-1}. Depending on the sign of the Z axis value, the hole is either pointing towards or away from the sheet's Z axis. From this, you can deduce if the hole is on the front face or the rear face of the tooling plate.