iLogic/api rule for subassembly constraints

iLogic/api rule for subassembly constraints

DJFore
Advocate Advocate
1,036 Views
2 Replies
Message 1 of 3

iLogic/api rule for subassembly constraints

DJFore
Advocate
Advocate

 

I have a main assembly that I want to place a sub assembly into. I cannot pre-define the sub assembly file name (because it based on requirement for the line) nor can I define the occurence.item # because I don't know where it will end up in the tree and I may have multiples. What I want to happen is when I place the sub assembly into the main it will prompt me in someway on placement to select a location. I have predefined in my main assembly two constant planes (LINE_TOP and a LINE_DEPTH plane) to constrain (mate) it to these two will be the same for all sub assemblies. In my main assembly I have also defined 10 other planes (my location) as L1_PLANE, L2_PLANE ..... L10_PLANE these are the ones I will need to select the plane name to tell the sub assembly which plane to constrain (mate) to. The mating planes in my sub assembly will be the origin planes. 

I have constrained parts in assemblies through use of ilogic/api. But I cannot figure out a good way to be prompted on placement to select a location and then the code know that the line that was just placed is the occurrence that I want to constrain to the defined plane that I select in the prompt.

 

Here is an example that might help the logic.

I have up to 10 buckets. I always want them to set on the floor and up against one wall, but I do not know the order of the buckets till I set them out.

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

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

Hi Dustin Fore,

 

Initially, plane should be selected from list "L1_PLANE, L2_PLANE ..... L10_PLANE". Then, subassembly to be added by specifying the path and matrix. Followed by adding mate constraint to origin plane of subassembly and selected plane.

 

Please find the sample code for the same in the following.

 

    Dim oAssyDoc As AssemblyDocument
    oAssyDoc = ThisApplication.ActiveDocument

    Dim oAssyDef As AssemblyComponentDefinition
    oAssyDef = oAssyDoc.ComponentDefinition

    'Plane need to be selected from the list "L1_PLANE, L2_PLANE ..... L10_PLANE"
    Dim selectedPlane As WorkPlane
    selectedPlane = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kWorkPlaneFilter, "Select a plane to constraint")

    Dim oM As Matrix = ThisApplication.TransientGeometry.CreateMatrix()

    Dim occ As ComponentOccurrence
    occ = oAssyDef.Occurrences.Add("Path of subassembly", oM)

    Dim occDef As AssemblyComponentDefinition
    occDef = occ.Definition

    Dim subAssemblyPlane As WorkPlane
    subAssemblyPlane = occDef.WorkPlanes.Item(2)

    Dim planeProxy As WorkPlaneProxy
    occ.CreateGeometryProxy(subAssemblyPlane, planeProxy)

    Call oAssyDef.Constraints.AddMateConstraint(planeProxy, selectedPlane, "0 in")

 

Please feel free to contact if there is any doubt.

 

Thanks and regards,

 

If solves your problem, click on "Accept as solution" / give a "kudo"


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 3 of 3

DJFore
Advocate
Advocate

CHANDRA,

That worked with a little tweaking which I have included so if anyone else wants it.

Thanks 

 Dim oAssyDoc As AssemblyDocument
    oAssyDoc = ThisApplication.ActiveDocument

    Dim oAssyDef As AssemblyComponentDefinition
    oAssyDef = oAssyDoc.ComponentDefinition

    'Plane need to be selected from the list "L1_PLANE, L2_PLANE ..... L10_PLANE"
    Dim selectedPlane1 As WorkPlane
    selectedPlane1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kWorkPlaneFilter, "Select a plane to constraint")
	Dim selectedPlane2 As WorkPlane
	selectedPlane2=oAssyDef.WorkPlanes.Item("LINE_TOP_PLANE")
	Dim selectedPlane3 As WorkPlane
    selectedPlane3=oAssyDef.WorkPlanes.Item("LINE_DEPTH")
	
	
    Dim oM As Matrix = ThisApplication.TransientGeometry.CreateMatrix()

	Dim oFileDlg As inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"
oFileDlg.DialogTitle = "Select a File"
oFileDlg.InitialDirectory = ThisDoc.Path
oFileDlg.CancelError = True
On Error Resume Next
oFileDlg.ShowOpen()
If Err.Number <> 0 Then
MessageBox.Show("File not chosen.", "Dialog Cancellation")
ElseIf oFileDlg.FileName <> "" Then
selectedfile = oFileDlg.FileName
End If

    Dim occ As ComponentOccurrence
    occ = oAssyDef.Occurrences.Add(selectedfile,oM)
	
    Dim occDef As AssemblyComponentDefinition
    occDef = occ.Definition

    Dim subAssemblyPlane1 As WorkPlane
    subAssemblyPlane1 = occDef.WorkPlanes.Item(1)
	Dim subAssemblyPlane2 As WorkPlane
    subAssemblyPlane2 = occDef.WorkPlanes.Item(2)
	Dim subAssemblyPlane3 As WorkPlane
    subAssemblyPlane3 = occDef.WorkPlanes.Item(3)

    Dim planeProxy1 As WorkPlaneProxy
    occ.CreateGeometryProxy(subAssemblyPlane1, planeProxy1)
	Dim planeProxy2 As WorkPlaneProxy
    occ.CreateGeometryProxy(subAssemblyPlane2, planeProxy2)
	Dim planeProxy3 As WorkPlaneProxy
    occ.CreateGeometryProxy(subAssemblyPlane3, planeProxy3)
		

    Call oAssyDef.Constraints.AddFlushConstraint(planeProxy1, selectedPlane1, "0")
	Call oAssyDef.Constraints.AddFlushConstraint(planeProxy2, selectedPlane2, "0")
	Call oAssyDef.Constraints.AddFlushConstraint(planeProxy3, selectedPlane3, "0")
0 Likes