Type Error when attempting to addDistanceDimension

Type Error when attempting to addDistanceDimension

peter6G3RQ
Explorer Explorer
590 Views
2 Replies
Message 1 of 3

Type Error when attempting to addDistanceDimension

peter6G3RQ
Explorer
Explorer

Hello,

 

I'm trying to create a script to allow me to sweep a largish number of curves with the same profile (that tapers along the length of the curve, but only in one dimension), but would like to be able to adjust the dimensions of that profile after the fact using parameters. I currently have it in a state where it will create the required profiles at each end of the curve based off of my User Parameters but I understand from this post that in order to have it directly reference the parameter (and thus be adjustable) I need to add dimensions to the sketch and link them to the parameters.

 

My defined user parameters for reference:

Parameters.png

 BSOx and BSOy are the size of the profile with all the others based off of them in order to draw a 3 point rectangle (not good with Python, only started using it this afternoon and was trying to keep things as simple as possible for myself, I'm sure it would be better to do it with math within the script). 

 

Here is the entire script:

 

 

import adsk.core, adsk.fusion, traceback
    
def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        if not design:
            ui.messageBox('It is not supported in current workspace, please change to MODEL workspace and try again.')
            return
        
        sel = ui.selectEntity('Select a path to create loft', 'Edges,SketchCurves')
        selObj = sel.entity
        comp = design.rootComponent
        
        userParams = design.userParameters

        # create path
        feats = comp.features
        chainedOption = adsk.fusion.ChainedCurveOptions.connectedChainedCurves
        if adsk.fusion.BRepEdge.cast(selObj):
            chainedOption = adsk.fusion.ChainedCurveOptions.tangentChainedCurves
        path = adsk.fusion.Path.create(selObj, chainedOption)
        path = feats.createPath(selObj)
        
        # create planes at each end
        planes = comp.constructionPlanes
        planeInput = planes.createInput()
        planeInput.setByDistanceOnPath(selObj, adsk.core.ValueInput.createByReal(0))
        plane1 = planes.add(planeInput)
        planeInput.setByDistanceOnPath(selObj, adsk.core.ValueInput.createByReal(1))
        plane2 = planes.add(planeInput)
        
        #create sketch for origin
        sketches = comp.sketches
        sketch = sketches.add(plane1)

        #create rectangle

    
        oCentre = plane1.geometry.origin
        oCentre = sketch.modelToSketchSpace(oCentre)
        oCorner1 = adsk.core.Point3D.create(userParams.itemByName('nBSOox').value,userParams.itemByName('nBSOoy').value)
        oCorner2 = adsk.core.Point3D.create(userParams.itemByName('BSOox').value,userParams.itemByName('nBSOoy').value)
        oCorner3 = adsk.core.Point3D.create(userParams.itemByName('BSOox').value,userParams.itemByName('BSOoy').value)
        oRect1 = sketch.sketchCurves.sketchLines.addThreePointRectangle(oCorner1,oCorner2,oCorner3)
        

        # Add a dimension constraint and edit it's parameter to be dependent on 'BSOx'.
        dims = sketch.sketchDimensions
        oRectDim = dims.addDistanceDimension(oCorner1, oCorner2, adsk.fusion.DimensionOrientations.AlignedDimensionOrientation, adsk.core.Point3D.create(0,-3,0))
        oRectDim.parameter.expression = 'BSOx'

        profile1 = sketch.profiles[0]
        
        #create sketch for termination end
        sketches = comp.sketches
        sketch = sketches.add(plane2)

        #create rectangle from centre and corner
        tCentre = plane2.geometry.origin
        tCentre = sketch.modelToSketchSpace(tCentre)
        tCorner1 = adsk.core.Point3D.create(userParams.itemByName('BSTx').value,userParams.itemByName('BSTy').value)
        sketch.sketchCurves.sketchLines.addCenterPointRectangle(tCentre, tCorner1)
        profile2 = sketch.profiles[0]

#Create Loft

        loft1 = comp.features.loftFeatures
        loftInput = loft1.createInput(adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        loftSectionsObj = loftInput.loftSections
        loftSectionsObj.add(profile1)
        loftSectionsObj.add(profile2)
        loftPath = loftInput.centerLineOrRails
        loftPath.addCenterLine(path)
        loftInput.isSolid = True

         # Create loft feature
        loft1.add(loftInput)
        
        
        app.activeViewport.refresh()

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 

My issue is with the lines

 

        # Add a dimension constraint and edit it's parameter to be dependent on 'radius'.
        dims = sketch.sketchDimensions
        oRectDim = dims.addDistanceDimension(oCorner1, oCorner2, adsk.fusion.DimensionOrientations.AlignedDimensionOrientation, adsk.core.Point3D.create(0,-3,0))
        oRectDim.parameter.expression = 'BSOx'

 

No matter what I seem to try, I get TypeError: Wrong number or type of arguments for overloaded function 'SketchDimensions_addDistanceDimension' when running the script. The effect was the same whether I used a centrepoint rectangle and tried to measure from the centre to the corner, or as it is now with an unnecessary number of different parameters in order to draw a 3 point rectangle (I thought it was maybe due to the points not being on the same horizontal line).

 

I believe, probably incorrectly, that my issue is with the orientation argument as I cannot fathom what could be wrong with the others as they are all defined points.

 

I've cobbled this together from various other scripts I've found so if there is a much easier way to achieve my desired outcome please let me know. 

 

Thanks in advance

Pete

 

Edit: Sorry, to clarify I have tried various different things for each of the arguments of addDistanceDimension; for orientation specifically I have tried (having seen them used elsewhere): 0, adsk.fusion.DimensionOrientations.HorizontalDimensionOrientation, I think one other attempt but I can't find it now

0 Likes
Accepted solutions (1)
591 Views
2 Replies
Replies (2)
Message 2 of 3

peter6G3RQ
Explorer
Explorer

So think I worked it out, for anyone else that comes looking the points I was using for the dimension were not SketchPoints, after adding SketchPoints at the locations of the Point3Ds it seems to be generating the dimension now. 

0 Likes
Message 3 of 3

BrianEkins
Mentor
Mentor
Accepted solution

That's right, sketch dimensions have to be between two sketch points.  Sketch dimensions are also acting as constraints and defining a relationship between geometry.  It doesn't make sense to create a dimension constraint out in space that's not constraining anything.

 

There are also existing sketch points you may not be aware of.  All sketch geometry is attached to sketch points.  If you create a line, two sketch points were automatically created and the line is attached to them.  The same for an arc; a center sketch point and one at each end. When sketch entities are connected they both connect to the same sketch point. You can get these sketch points from the various sketch entities and you can use them as input for the sketch dimensions.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes