Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Creating JointOrigin

Anonymous

Creating JointOrigin

Anonymous
Not applicable

Hello,

I'm trying to figure out how to add a joint origin using a sketch point and a construction axis, basically the API equivalent of pre-selecting the sketch point and construction axis in the UI.

 

I have tried creating a joint origin input using the point and then aligning the z axis entity to the construction axis, but it just doesn't work.

 

can anyone help? 

0 Likes
Reply
826 Views
9 Replies
Replies (9)

marshaltu
Autodesk
Autodesk

Hello,

 

I did a testing with what you were saying. It worked well in my side. It would be great if you can provide the codes to demo the issue you said. 

 

I created a sketch with one sketch point and a work axis. The joint origin can be created successfully with the sample codes as below.

 

Thanks,

Marshal

 

import adsk.core, adsk.fusion, traceback
 
def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        
        design = adsk.fusion.Design.cast(app.activeProduct)
        sketch = design.rootComponent.sketches.itemByName('Sketch1')
        sketchpt = None
        for pt in sketch.sketchPoints:
            if pt.isVisible:
                sketchpt = pt
        workaxis = design.rootComponent.constructionAxes.item(0)
        
        input = design.rootComponent.jointOrgins.createInput(adsk.fusion.JointGeometry.createByPoint(sketchpt))
        input.zAxisEntity = workaxis
        design.rootComponent.jointOrgins.add(input)
 
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


Marshal Tu
Fusion Developer
>
0 Likes

Anonymous
Not applicable

Hi Marshal,

 

here's my code, the problem has got to be when I try to set the zAxisEntity alignment; if I comment out the switch statement the joint origin is created and only fails if I use the switch statement. The endpoint I pass in isn't situated on the axis, could that be the problem? Or have I made a mistake acquiring the construction axis?

 

Ptr<JointOrigin> ScaffoldingAssemble::AddJointOriginToAxis(Ptr<Component> component, Ptr<ConstructionPoint> endPoint, AxisAlignment alignment, string name)
{
	Ptr<JointOrigins> jointOrigins = component->jointOrgins();
	Ptr<JointOriginInput> jointOriginInput = jointOrigins->createInput(JointGeometry::createByPoint(endPoint));

	switch (alignment)
	{
	case AxisAlignment::xAxis:
		jointOriginInput->zAxisEntity(component->xConstructionAxis());
		break;
	case AxisAlignment::yAxis:
		jointOriginInput->zAxisEntity(component->yConstructionAxis());
		break;
	case AxisAlignment::zAxis:
		jointOriginInput->zAxisEntity(component->zConstructionAxis());
		break;
	default:
		break;
	}

	Ptr<JointOrigin> jointOrigin = jointOrigins->add(jointOriginInput);

	jointOrigin->name(name);

	return jointOrigin;
}

 

0 Likes

Anonymous
Not applicable

Hi Marshal,

Been working on the code and discovered that it will work if I align the zAxisEntity to the zConstructionAxis or the xAxisEntity to the xConstructionAxis, but this isn't what I want. I'm trying to align the zAxisEntity with the xConstructionAxis so that when the joint origins is used I get a rotary motion in a vertical plane (up and down) rather than a horizontal plane (let and right); I am using a z axis up model orientation.

 

0 Likes

marshaltu
Autodesk
Autodesk

Hello,

 

I guess the problem was because the component you were using was sub component. You have to create proxy object for construction axis in the case because we need assembly context(e.g. transform) to create joint geometry. 

 

I did a testing with sub component. It works well after I create a proxy object for the construction axis.

 

Thanks,

Marshal

 

import adsk.core, adsk.fusion, traceback
 
def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        
        design = adsk.fusion.Design.cast(app.activeProduct)
        sketch = design.rootComponent.sketches.itemByName('Sketch1')
        sketchpt = None
        for pt in sketch.sketchPoints:
            if pt.isVisible:
                sketchpt = pt
        
        occ = design.rootComponent.occurrences.item(0)
        workaxis = occ.component.xConstructionAxis.createForAssemblyContext(occ)
        
        input = design.rootComponent.jointOrgins.createInput(adsk.fusion.JointGeometry.createByPoint(sketchpt))
        input.zAxisEntity = workaxis
        design.rootComponent.jointOrgins.add(input)
 
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


Marshal Tu
Fusion Developer
>
0 Likes

Anonymous
Not applicable

Hello Marshal,

I think I'm still doing something wrong, I cannot get it to work. Your example uses the root component, but I'm not creating the joint origin in the root component and so tried applying your example to my component instance......... just can't get it to work; I cannot get an occurrence.  

0 Likes

marshaltu
Autodesk
Autodesk

Hello,

 

What error were you seeing? I saw the following error when I tried to create joint origin based on construction point + construction axis. It worked well with sketch point + construction axis. It looks be a bug in our side. We will investigate the issue. 

 

Screen Shot 2017-07-21 at 12.54.05 PM.png

import adsk.core, adsk.fusion, traceback
 
def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        
        design = adsk.fusion.Design.cast(app.activeProduct)      
        occ = design.rootComponent.occurrences.item(0)
        
        comp = occ.component       
        #occsForComp = design.rootComponent.allOccurrencesByComponent(comp)
        
        workpoint = comp.constructionPoints.item(0)
        workaxis = comp.xConstructionAxis.createForAssemblyContext(occ)
        
        input = comp.jointOrgins.createInput(adsk.fusion.JointGeometry.createByPoint(workpoint))
        input.zAxisEntity = workaxis
        comp.jointOrgins.add(input)
 
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

Thanks,

Marshal



Marshal Tu
Fusion Developer
>
0 Likes

Anonymous
Not applicable

Hi Marshal,

 

I'm not actually seeing an error message, I just end up with a Null for the joint origin when I call the Add. I guess I need to re-think how I generate my construction geometry and come at the problem from a different perspective. 

 

Thanks for all the help.

0 Likes

marshaltu
Autodesk
Autodesk

Hello,

 

Sorry, I was not aware of the difference between Python and C++ api. There is no explicit error message for C++ api calling.

 

Please use Application::getLastError() to get detailed error information. Then we would able able to judge what's root cause to return nullptr joint origin object there.

 

Thanks,

Marshal



Marshal Tu
Fusion Developer
>
0 Likes

Anonymous
Not applicable

Hi Marshal,

I went back to the drawing board............ well Fusion, over the weekend and reconsidered the modelling approach. After re-reading your post and looking at the model in Fusion, I decided to drop the construction point and axis in favour of a sketch and sketch point; so I have ripped out all the code associated to the old methodology. Sketch orientation relative to XYZ meant I had to make some small modifications to point generation, can't count on the sketch always being aligned Z up but that was all and the new method is working well so.

 

I think from my perspective at least that this issue is closed, but thank you again for all the help.

 

 

 

0 Likes