1 Reply Latest reply on Jul 10, 2016 7:31 PM by Alin Vargatu

    changing orientation of user defined coordinate system

    Yuvaraj Kasi

      Hi,

      need help on creating a macro to create a Coordinate System on a sketch point and align its Y-Axis to a line in XZ-plane (turning Y-axis to 90 degrees).

      (below pic shows my requirment)

      UCS alignment.jpg

       

      in the below code, the CS point is created but alignment is not done. I am not sure how to use "Set swFeat = swFeatMgr.CreateCoordinateSystem(skPoint, sx, sy, sz)"

       

      '******************************************************************************************************************************************

      Dim swApp As SldWorks.SldWorks
      Dim Part As SldWorks.ModelDoc2
      Dim boolstatus As Boolean
      Dim longstatus As Long, longwarnings As Long
      Dim swModel As SldWorks.ModelDoc2
      Dim swFeat As SldWorks.Feature
      Dim swFeatMgr As SldWorks.FeatureManager
      Dim swSelMgr As SldWorks.SelectionMgr
      Dim x1, y1, z1 As Double
      Dim sy As Object


      Sub main()

          Set swApp = Application.SldWorks
          Set Part = swApp.ActiveDoc
          Set swModel = swApp.ActiveDoc
          Set swSelMgr = Part.SelectionManager
          Set swFeatMgr = swModel.FeatureManager

          boolstatus = Part.Extension.SelectByID2("Point1@Sketch1", "EXTSKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0)
          Dim skPoint As SketchPoint
          Set skPoint = swSelMgr.GetSelectedObject6(1, -1)

            

          boolstatus = Part.Extension.SelectByID2("Line1@Sketch1", "EXTSKETCHSEGMENT", 0, 0, 0, False, 1, Nothing, 0)
          Set sy = swSelMgr.GetSelectedObject6(2, -1)

          Set swFeat = swFeatMgr.CreateCoordinateSystem(skPoint, sx, sy, sz)

      End Sub

      '******************************************************************************************************************************************

        • Re: changing orientation of user defined coordinate system
          Alin Vargatu

          Did you get an answer?

           

          I need a similar macro that will:

           

          1. Ask the user to select a planar face or a plane. The location of the click will be used in the macro (the point on the face).

          2. Create a 2D Sketch on that face or plane

          3. Draw a centerline circle with a radius of 6mm on the location of the click from step 1. No need to apply a diameter dimension.

          4. Draw an 1" long line from the location of the click to an arbitrary direction, about 30 degree from the horizontal direction. Dimension the line as 1".

          5. Apply an angle dimension between the line and the horizontal direction.

          6. Make that angle equal to zero

          7. Exit the sketch

          8. Name the sketch as "CS_Sketch" and color it red

           

          9. Create a coordinate system as follows:

           

          10. Name the new coordinate system as CLAMP_CS