- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, Folks.
I'm struggling to wrap my head around operations with components that are children of components. Specifically, in this case, I want to make a rigid joint between two subcomponents from different parents.
Following this example, I can create a rigid group from components in the root component with no problem.
I can get it to work if things are all in the root and there are no sub-components involved:
root
|
+-comp1
|
+-subcomp1
|
+-comp2
|
--subcomp2
But it fails if I put the subcomponents one or more layers deeper, like this:
root
|
+ comp1
| |
| -subcomp1
|
- comp2
|
-subcomp2
subcomp1 and subcomp2 are actually other models inserted into this one.
So this works:
import adsk.core, adsk.fusion, adsk.cam, traceback
def run(context):
#Get system objects
app = adsk.core.Application.get()
project = app.data.activeProject
design = adsk.fusion.Design.cast(app.activeProduct)
root = design.rootComponent
trans = adsk.core.Matrix3D.create()
#Create top level components
occ = root.occurrences.addNewComponent(trans)
comp1 = occ.component
comp1.name = 'comp1'
occ = root.occurrences.addNewComponent(trans)
comp2 = occ.component
comp2.name = 'comp2'
# Get folder containing other models
for folder in project.rootFolder.dataFolders:
if folder.name == "ExtComps":
ext_folder = folder
# Import each of the other models.
for file in ext_folder.dataFiles:
if file.name == 'Sphere':
file_to_insert = file
sub_comp1 = root.occurrences.addByInsert(file_to_insert, trans, True)
elif file.name == 'Cube':
file_to_insert = file
sub_comp2 = root.occurrences.addByInsert(file_to_insert, trans, True)
#Create a collection
occs = adsk.core.ObjectCollection.create()
occs.add(sub_comp1)
occs.add(sub_comp2)
#Create a rigid group.
isIncludeChildren = True
rigidGroups_ = root.rigidGroups
rigidGroups_.add(occs, isIncludeChildren)
But this fails:
import adsk.core, adsk.fusion, adsk.cam, traceback
def run(context):
#Get system objects
app = adsk.core.Application.get()
project = app.data.activeProject
design = adsk.fusion.Design.cast(app.activeProduct)
root = design.rootComponent
trans = adsk.core.Matrix3D.create()
#Create top level components
occ = root.occurrences.addNewComponent(trans)
comp1 = occ.component
comp1.name = 'comp1'
occ = root.occurrences.addNewComponent(trans)
comp2 = occ.component
comp2.name = 'comp2'
# Get folder containing other models
for folder in project.rootFolder.dataFolders:
if folder.name == "ExtComps":
ext_folder = folder
# Import each of the other models.
for file in ext_folder.dataFiles:
if file.name == 'Sphere':
file_to_insert = file
sub_comp1 = comp1.occurrences.addByInsert(file_to_insert, trans, True)
elif file.name == 'Cube':
file_to_insert = file
sub_comp2 = comp2.occurrences.addByInsert(file_to_insert, trans, True)
#Create a collection
occs = adsk.core.ObjectCollection.create()
occs.add(sub_comp1)
occs.add(sub_comp2)
#Create a rigid group.
isIncludeChildren = True
rigidGroups_ = root.rigidGroups
rigidGroups_.add(occs, isIncludeChildren)
-> "RuntimeError: 5 : Provided input paths or alignments are not valid."
It inserts the external files just fine, but hits a wall when I try to create the rigid group. It also fails if I put both of the external objects under the same parent (eg comp1).
It's frustrating, because I can make exactly that rigid group using the GUI with no issues, so it's an allowed action, but I just can't see what I need to do in the API to achieve the same result.
Can anyone tell me what I've missed?
Solved! Go to Solution.