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: 

How to access joints within instances of a component?

2 REPLIES 2
Reply
Message 1 of 3
RogerInHawaii
370 Views, 2 Replies

How to access joints within instances of a component?

When you have a JointA within ComponentX and you create instances of ComponentX you get ComponentX:1, ComponentX:2,  ComponentX:3 and so on. But within each and every one of those component instances the name of the joint is always the same "JointA". The question is, What has to be done in order to get access to, for example, JointA within instance ComponentX:2? Is there some sample code that will show me how to do  that?

I'm writing my Add-In Script in C++, so an example of how to do it in C++ would be most helpful.

2 REPLIES 2
Message 2 of 3
BrianEkins
in reply to: RogerInHawaii

The first thing I would recommend is to read the topic in the API help about components, occurrences, and proxies.  

 

After reading that hopefully, you'll be able to see that there is only one joint, the one in ComponentX.  However, in the assembly, you're viewing that component through an occurrence.  There is a unique occurrence for each instance of the component; ComponentX:1, ComponentX:2, etc.  You can access the joint in the context of each occurrence as a "proxy" of the joint.  If you use the joints collection on the Occurrence object, it will return joint proxies for the joints in the component that are relative to that occurrence.  Hopefully, that makes a little sense.  

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 3

OK, I've been able to sequence my way down through the hierarchy of components/occurrences, within my Add-Ins C++ Script, and now have indeed gotten access to the Occurrence that I want (Rocket Engine Unit:1, shown in green), the one that has the Joint that I'm trying to gain access to ("Rev Rocket Engine Unit", shown in red).

Accessing Joints in instances 1.png

 

But when I access that Occurrence's joints property it has ZERO entries. When I access  the Occurrence's asBuiltJoints property the list is NULL. Yet, according to the Browser hierarchy, there it is, the "Rev Rocket Engine Unit 1" joint that I want to gain access to.

Here's the method I wrote to get access to the joint. It gets passed in the Occurrence within which the joint resides plus the name of the joint I'm trying to access. And even though the Joint does indeed reside with the occurrence (according to the Browser) my method fails to access it. (The "Show" method simply displays the text in a dialog box so I can track along with what it's doing).

Does anyone have any idea what I'm doing wrong, or why the joint shows in the browser but seems to be not accessible via the API?

//
// GET JOINT NAME FROM OCCURRENCE
//
Ptr<Joint> GetJointByNameFromOccurrence(Ptr<Occurrence> TheOccurrenceToSearch, std::string DesiredJointName)

{
	// We first look in the (normal) joints list and then in the As Built Joints List.
	Show("IN GetJointByNameFromOccurrence(" + TheOccurrenceToSearch->name() + ", " + DesiredJointName);

	Ptr<Joint> TheFoundJoint = NULL; // Assume that we're not going to find it.
	
	Ptr<JointList> JointsList = TheOccurrenceToSearch->joints();

	if (JointsList)
	{
		Show("IN GetJointByNameFromOccurrence looking for " + DesiredJointName + "\nJointsList has " + std::to_string(JointsList->count()) + "regular joints");
		TheFoundJoint = JointsList->itemByName(DesiredJointName);
		if (TheFoundJoint)
		{
			return TheFoundJoint;
		}
	}
	else
	{
		Show("NO REGULAR JOINTS");
	}

	Ptr<JointList> AsBuiltJointsList = TheOccurrenceToSearch->asBuiltJoints();

	if (AsBuiltJointsList)
	{
		Show("IN GetJointByNameFromOccurrence looking for " + DesiredJointName + "\nAsBuiltJointsList has " + std::to_string(AsBuiltJointsList->count()) + "joints");
		TheFoundJoint = AsBuiltJointsList->itemByName(DesiredJointName);
	}
	else
	{
		Show("NO AS-BUILT JOINTS");
	}
	return TheFoundJoint;
}






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