Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Don't create joint

3 REPLIES 3
Reply
Message 1 of 4
-pezi-
240 Views, 3 Replies

Don't create joint

I want to create a Joint using two JointOrigin, but I can't make it work. Everything seems to be fine just Ptr <Joint> joint = joints-> add (jointInput); will not return anything. Can you advise me where I make a mistake? I attach a part of the script that I am trying to create a Joint

Ptr occList = rootComp->allOccurrences();
	if (!occList)
		return false;
	Ptr comp;
	for (size_t i = 0; i < occList->count(); ++i)
	{
		if (occList->item(i)->name() == "MainComponent:1")
			comp = occList->item(i)->component();
	}

	Ptr occ = comp->occurrences()->item(1)->childOccurrences()->itemByName("Hinge cup Wood Screw:1");
	if (!occ)
		return false;
	Ptr joinGeom1 = occ->component()->jointOrigins()->item(0);
	if (!joinGeom1)
		return false;	
	Ptr joinGeom2 = comp->occurrences()->itemByName("SubCopmponent:1")->component()->jointOrigins()->item(0);
	if (!joinGeom2)
		return false;
	Ptr joints = comp->joints();
	if (!joints)
		return false;
	Ptr jointInput = joints->createInput(joinGeom1, joinGeom2);
	if (!jointInput)
		return false;
	jointInput->setAsRigidJointMotion(); 
	
	Ptr joint = joints->add(jointInput);
	if (!joint)
		return false;

And here is a screenshot of the document where I run the script

obrazek.png

3 REPLIES 3
Message 2 of 4
masounmardini
in reply to: -pezi-

Hi,

I'm not a C programmer my preferred language is Python, but when looking at you code and comparing it to mine 

I found you are missing one piece of code that I use when making joints

 

after creating joint geometry  for the hinge part you must use

jointGeom1->createForAssmeblyContext(occurrence)

 

Hopefully that will help you!!

 

Masoun

Message 3 of 4
-pezi-
in reply to: masounmardini

Thank you for your advice, but it doesn't seem to be the only reason why it doesn't work for me. Because even after using CreateForAssemblyContext I was unable to get the code up and running. Could you please add the code in Python that will make the joint between the hinge and the board, using the JointOrigins defined in them as shown in the attached picture. I am also attaching my script, which I failed to put into operation.obrazek.png

	Ptr<Application> app = Application::get();
	if (!app)
		return false;

	ui = app->userInterface();
	if (!ui)
		return false;

	Ptr<Product> product = app->activeProduct();
	if (!product)
		return false;

	Ptr<Design> design = product;
	if (!design)
		return false;

	// Get the root component of the active design
	Ptr<Component> rootComp = design->rootComponent();
	if (!rootComp)
		return false;

	Ptr<OccurrenceList> occList = rootComp->allOccurrences();
	if (!occList)
		return false;
	Ptr<Occurrence> baseOcc;
	Ptr<Component> comp;
	for (size_t i = 0; i < occList->count(); ++i)
	{
		if (occList->item(i)->name() == "Component1:1")
		{
			baseOcc = occList->item(i);
			comp = occList->item(i)->component();
		}
	}

	
	Ptr<Occurrence> higeOcc = comp->occurrences()->itemByName("OverlayHinge v3:1");
	Ptr<Occurrence> occ1 = comp->occurrences()->item(1)->childOccurrences()->itemByName("Hinge cup Wood Screw:1");
	if (!occ1)
		return false;
	Ptr<JointOrigin> joinGeom1 = occ1->component()->jointOrigins()->item(0);
	if (!joinGeom1)
		return false;
	Ptr<JointOrigin> aa = joinGeom1->createForAssemblyContext(occ1);

	Ptr<Occurrence> occ2 = comp->occurrences()->itemByName("SubComponent1:1");
	if (!occ2)
		return false;
	Ptr<JointOrigin> joinGeom2 = occ2->component()->jointOrigins()->item(0);
	if (!joinGeom2)
		return false;
	Ptr<JointOrigin> bb = joinGeom2->createForAssemblyContext(occ2);

	Ptr<Joints> joints = comp->joints();
	if (!joints)
		return false;
	Ptr<JointInput> jointInput = joints->createInput(aa, bb);
	if (!jointInput)
		return false;
	jointInput->setAsRigidJointMotion();

	Ptr<Joint> joint = joints->add(jointInput);
	if (!joint)
		return false;

	return true;
Message 4 of 4
masounmardini
in reply to: -pezi-

Sorry  I don't remember exactly how I did it (this was a year ago,  but I rememeber it was pain in the ***)

see the comments in deferent colors.

product = app.activeProduct
design = adsk.fusion.Design.cast(product)
rootComp = design.rootComponent
allOccs = rootComp.occurrences            
boltOcc = allOccs.item(allOccs.count-1) # Now I'm just getting the last occurrence drawn of the moving part 
boltJointGeom = boltOcc.component.jointOrigins.item(0) #Collect J.O. of the moving part
boltJointGeom = boltJointGeom.createForAssemblyContext (boltOcc) # make it moveable
if (Etype == 'jointOrigin'): # This for my program it has several type of joint Entity
      partJointGeom = insert.geometry  #This is the J.O. geometry of the master part
      jointInput = boltOcc.component.joints.createInput(boltJointGeom, partJointGeom)
      jointInput.offset = adsk.core.ValueInput.createByReal(-self.zOffset)
      jointInput.isFlipped = True
      jointInput.isVisible = False            
      joint = boltOcc.sourceComponent.joints.add(jointInput) # here maybe I skipped this instruction "sourceComponent" in my last reply

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report