SW 2005 API Online Tutorial toubleshooting

Discussion in 'SolidWorks' started by Doug, Nov 4, 2004.

  1. Doug

    Doug Guest

    Hi everyone:
    An API question. I like to play with API once in a while, and thought I
    would check out the 2005 SolidWorks Online Tutorial. I got the same error I
    got in SW2004:
    The Macro does not record anything entered in the properties manager (Step
    8 - In the PropertyManager, set Radius to 15). The circle size is recorded
    as the drag size. They sample macro provided gives circle size is 11.6 -
    they did not check?
    I know there are SolidWorks objects, methods, and properties that will set
    the size to 15, but it seems the program should do what they say it does.


    Further on:
    Creating a Generic Cut-Extrude Program

    From the sample code - swSelFaces is a variable not found. I am not good
    enough with API to figure out where it is created. There is an assumption
    that a selection has been made, but I do not see where.

    Here is the sample code they give:

    You can replace the current code in the Code window by either modifying the
    code as shown or by copying the code and pasting it in the Code Window.
    Review all comments and code to understand what is being modified and why.
    See the SolidWorks API and Add-Ins Help for details about the SolidWorks
    objects, methods, and properties.


    ' VARIABLES TO KEEP
    ' Declare all variables
    Option Explicit

    ' Early bound variables
    Dim swApp As SldWorks.SldWorks
    Dim Part As SldWorks.ModelDoc2
    Dim boolstatus As Boolean

    ' VARIABLES TO ADD
    Dim SelectedObject As Object
    Dim SelectCoords As Variant
    Dim CircleSketch As SldWorks.sketch
    Dim MathUtil As SldWorks.MathUtility
    Dim SketchPoint As SldWorks.MathPoint
    Dim Transform As SldWorks.MathTransform

    Dim dx As Double
    Dim dy As Double
    Dim dz As Double

    ' CODE TO KEEP
    Sub main()

    ' Connect to currently active SolidWorks document
    Set swApp = Application.SldWorks

    Set Part = swApp.ActiveDoc

    ' CODE TO COMMENT OUT
    'boolstatus = Part.Extension.SelectByID2("", "FACE" 0.002071542165481, _
    ' 0.2199999999999, 0.001163233015006, False, 0, Nothing

    ' CODE TO ADD
    ' Get coordinates of the point selected
    SelectCoords = Part.SelectionManager.GetSelectionPoint(1)


    ' If face is selected, then create the cut-extrude; else, stop execution
    Set SelectedObject = Part.SelectionManager.GetSelectedObject5(1)
    If Part.SelectionManager.GetSelectedObjectType2(1) = swSelFACES Then

    ' CODE TO KEEP
    'Insert new sketch
    Part.InsertSketch2 True

    ' CODE TO COMMENT OUT
    'Part.ClearSelection2 True
    'Part.CreateCircle 0, 0, 0, 0.01493904319338, 0.004501031521355, 0
    'Part.ClearSelection2 True
    'boolstatus = Part.Extension.SelectByID2("Arc1", "SKETCHSEGMENT", _
    '0, 0, 0, False, 0, Nothing)

    ' CODE TO ADD
    ' Get MathPoint to use when transforming point from model space to sketch
    space
    Set MathUtil = swApp.GetMathUtility
    Set SketchPoint = MathUtil.CreatePoint(SelectCoords)

    ' Get reference to the sketch
    Set CircleSketch = Part.GetActiveSketch2()

    ' Translate sketch point into sketch space
    Set Transform = CircleSketch.ModelToSketchTransform
    Set SketchPoint = SketchPoint.MultiplyTransform(Transform)

    ' Retrieve coordinates of the sketch point
    dx = SketchPoint.ArrayData(0)
    dy = SketchPoint.ArrayData(1)
    dz = SketchPoint.ArrayData(2)

    ' Use Part.CreateCircleByRadius2 instead of Part.CreateCircle
    ' because Part.CreateCircleByRadius2 sketches a circle
    ' centered on a sketch point and lets you specify a radius
    Part.CreateCircleByRadius2 dx, dy, dz, 0.015

    ' CODE TO COMMENT OUT
    'Part.FeatureManager.FeatureCut True, False, False, 0, 0, 0.025, _
    ' 0.025, True, False, False, False, 0.2617993877992, _
    ' 0.2617993877992, False, False, False, False, 0, 1, 1
    'Part.SelectionManager.EnableContourSelection = 0

    ' CODE TO ADD
    ' Create cut-extrude without draft by specifying
    ' 0 for 12th and 13th arguments
    Part.FeatureManager.FeatureCut True, False, False, 0, 0, 0.025, _
    0.01, True, False, False, False, 0, 0, False, False, _
    False, False, 0, 1, 1

    End If

    ' CODE TO KEEP
    End Sub
     
    Doug, Nov 4, 2004
    #1
  2. swSelFACES is a constant it is defined in the SolidWorks Constant type
    library. You have to add it to your references for it to have a value.

    As for the record macro it is pretty limited it can be quite a help at times
    I would suggest using it only as a reference. If you want to change a
    feature you need to select it handle the selection and pass it to the proper
    type of object and use that object's methods to modify it.

    regards,

    Corey
     
    Corey Scheich, Nov 4, 2004
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.