PROBLEMS WITH A CONSTRAINT BETWEEN WORK PLANES

PROBLEMS WITH A CONSTRAINT BETWEEN WORK PLANES

Luis_Pacheco_3D
Advocate Advocate
238 Views
2 Replies
Message 1 of 3

PROBLEMS WITH A CONSTRAINT BETWEEN WORK PLANES

Luis_Pacheco_3D
Advocate
Advocate

I Wrote this code to create a Plane and constrained it with a Work Plane in a Part. This works until the last line of the code where it throws me an error.

 


	oPart  = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select a Part") 
	oPlane1 = oPart.Definition.WorkPlanes.Item("UCS_TOP: XY Plane")
	MessageBox.Show(oPlane1.name, "Title")
	

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
Try
		oAsmCompDef.WorkPlanes.Item("Plano_2").Delete
Catch
	'Do nothing
End Try

oPlane2 = oAsmCompDef.WorkPlanes.AddFixed(oTG.CreatePoint(0,0,0),oTG.CreateUnitVector(0,0,1),oTG.CreateUnitVector(0,1,0),False)
oPlane2.Name = "Plano_2"

MessageBox.Show(oPart.name , "Title")

'Constraints.AddMate("Mate:20", "", oPlane2.Name, "SKELETON_SC_JM_02:1" , "UCS_TOP: XY Plane")
Constraints.AddMate("Mate:20", "", oPlane2.Name, oPart.name, "UCS_TOP: XY Plane")

 

If I activate the line 23, the rule works correctly, but if I activate the line 24 ( deactivating the line 23). The code does everything except the constraint, showing the following error

Error in rule: Rule3, in document: SC_JM_02.iam

Unable to cast object of type 'System.String' to type 'Autodesk.iLogic.Types.ComponentArgument'.

 

How can I fix it? 

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

A.Acheson
Mentor
Mentor

There seems to be too many arguments in your ilogic function and they are of the wrong type.

 

Try this

 

Edit, I missed the component referencing. See forum post here

Constraints.AddMate("", "oPart.Name", "oPlane1.Name", "", "oPlane2.Name",
                    0 mm)

 

 

Another method to do this is us going the API directly. It will use the object directly rather than by name. 

   oAsmCompDef.Constraints.AddMateConstraint(oPlane1, oPlane2, 0)

 The API sample is shown here written in VBA launguage.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 3

Luis_Pacheco_3D
Advocate
Advocate
Accepted solution

The code is a test to complement a bigger code, I fix it today,I just added these 3 lines, and works.

 

Dim oPlane1 As WorkPlane
Dim aDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oPart As ComponentOccurrence

 

Thank you for your help.

 

 

 

 

0 Likes