Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create ILogic constraints between parts based on 3 planes chosen by the user

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
haphanthanhtam.work
440 Views, 6 Replies

Create ILogic constraints between parts based on 3 planes chosen by the user

haphanthanhtam.work
Enthusiast
Enthusiast

i want to create mate for 3 face of part in assembly to quickly do my work
i have below code but it is not working

Dim asmDoc As AssemblyDocument
asmDoc = ThisApplication.ActiveDocument

Dim part1 As ComponentOccurrence
part1 = asmDoc.ComponentDefinition.Occurrences.Item(1)

Dim part2 As ComponentOccurrence
part2 = asmDoc.ComponentDefinition.Occurrences.Item(2)

Dim selectedPlane1 As WorkPlane
selectedPlane1 = ThisApplication.CommandManager.Pick(kWorkPlaneFilter, "Select the first plane")

Dim selectedPlane2 As WorkPlane
selectedPlane2 = ThisApplication.CommandManager.Pick(kWorkPlaneFilter, "Select the second plane")

Dim selectedPlane3 As WorkPlane
selectedPlane3 = ThisApplication.CommandManager.Pick(kWorkPlaneFilter, "Select the third plane")

Dim constraintGroup As GeometricConstraintGroup
constraintGroup = asmDoc.ComponentDefinition.Constraints.AddMateConstraint(part1, part2, kFlushMate, selectedPlane1, selectedPlane2, selectedPlane3)

Select faceSelect face

 

affteraffter

 

0 Likes

Create ILogic constraints between parts based on 3 planes chosen by the user

i want to create mate for 3 face of part in assembly to quickly do my work
i have below code but it is not working

Dim asmDoc As AssemblyDocument
asmDoc = ThisApplication.ActiveDocument

Dim part1 As ComponentOccurrence
part1 = asmDoc.ComponentDefinition.Occurrences.Item(1)

Dim part2 As ComponentOccurrence
part2 = asmDoc.ComponentDefinition.Occurrences.Item(2)

Dim selectedPlane1 As WorkPlane
selectedPlane1 = ThisApplication.CommandManager.Pick(kWorkPlaneFilter, "Select the first plane")

Dim selectedPlane2 As WorkPlane
selectedPlane2 = ThisApplication.CommandManager.Pick(kWorkPlaneFilter, "Select the second plane")

Dim selectedPlane3 As WorkPlane
selectedPlane3 = ThisApplication.CommandManager.Pick(kWorkPlaneFilter, "Select the third plane")

Dim constraintGroup As GeometricConstraintGroup
constraintGroup = asmDoc.ComponentDefinition.Constraints.AddMateConstraint(part1, part2, kFlushMate, selectedPlane1, selectedPlane2, selectedPlane3)

Select faceSelect face

 

affteraffter

 

Tags (2)
Labels (1)
  • mate
6 REPLIES 6
Message 2 of 7

A.Acheson
Mentor
Mentor

Hi @haphanthanhtam.work 

 

I noticed a few mistakes you have,

  1. You were picking workplanes and not faces
  2. You were picking occurrences which is not required.
  3. GeometricConstraintGroup is not an object within the API

Here is a method that allows multiple constraints.

 

Dim asmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim face1 As Face 
Dim face2 As Face
Dim mate1 As MateConstraint

While True
	face1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select the first face")
	
	' Exit loop if nothing selected
	If face1 Is Nothing Then Exit While
		
	face2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select the second face")

	' Create the insert constraint between the parts.
	mate1 = asmDoc.ComponentDefinition.Constraints.AddMateConstraint(face1, face2, 0)
End While

 

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

Hi @haphanthanhtam.work 

 

I noticed a few mistakes you have,

  1. You were picking workplanes and not faces
  2. You were picking occurrences which is not required.
  3. GeometricConstraintGroup is not an object within the API

Here is a method that allows multiple constraints.

 

Dim asmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim face1 As Face 
Dim face2 As Face
Dim mate1 As MateConstraint

While True
	face1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select the first face")
	
	' Exit loop if nothing selected
	If face1 Is Nothing Then Exit While
		
	face2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select the second face")

	' Create the insert constraint between the parts.
	mate1 = asmDoc.ComponentDefinition.Constraints.AddMateConstraint(face1, face2, 0)
End While

 

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

haphanthanhtam.work
Enthusiast
Enthusiast

Hi @A.Acheson 
it's almost exact. I edited the code to suit me 

Dim asmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim face1 As Face 
Dim face2 As Face
Dim mate1 As MateConstraint


	face1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select the first face")
	
	' Exit loop if nothing selected
	
		
	face2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select the second face")

	' Create the insert constraint between the parts.
	mate1 = asmDoc.ComponentDefinition.Constraints.AddMateConstraint(face1, face2, 0)
	
	
	
	
	face3 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select the 3 face")
	
	' Exit loop if nothing selected
	
		
	face4 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select the 4 face")

	' Create the insert constraint between the parts.
	mate2 = asmDoc.ComponentDefinition.Constraints.AddMateConstraint(face3, face4, 0)
	
	
	
	
	face5 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select the 5 face")
	
	' Exit loop if nothing selected
	
		
	face6 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select the 6 face")

	' Create the insert constraint between the parts.
	mate3 = asmDoc.ComponentDefinition.Constraints.AddPlushConstraint(face5, face6, 0)

I need to edit this line to look like image
Can you helpe me!!

mate3 = asmDoc.ComponentDefinition.Constraints.AddPlushConstraint(face5, face6, 0)

 Capture.PNG

0 Likes

Hi @A.Acheson 
it's almost exact. I edited the code to suit me 

Dim asmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim face1 As Face 
Dim face2 As Face
Dim mate1 As MateConstraint


	face1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select the first face")
	
	' Exit loop if nothing selected
	
		
	face2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select the second face")

	' Create the insert constraint between the parts.
	mate1 = asmDoc.ComponentDefinition.Constraints.AddMateConstraint(face1, face2, 0)
	
	
	
	
	face3 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select the 3 face")
	
	' Exit loop if nothing selected
	
		
	face4 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select the 4 face")

	' Create the insert constraint between the parts.
	mate2 = asmDoc.ComponentDefinition.Constraints.AddMateConstraint(face3, face4, 0)
	
	
	
	
	face5 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select the 5 face")
	
	' Exit loop if nothing selected
	
		
	face6 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select the 6 face")

	' Create the insert constraint between the parts.
	mate3 = asmDoc.ComponentDefinition.Constraints.AddPlushConstraint(face5, face6, 0)

I need to edit this line to look like image
Can you helpe me!!

mate3 = asmDoc.ComponentDefinition.Constraints.AddPlushConstraint(face5, face6, 0)

 Capture.PNG

Message 4 of 7

A.Acheson
Mentor
Mentor

You have a spelling mistake here

 

mate3 = asmDoc.ComponentDefinition.Constraints.AddPlushConstraint(face5, face6, 0)

 

see API Help here

 

AssemblyConstraints.AddFlushConstraintEntityOne As Object, EntityTwo As Object, Offset As Variant, [BiasPointOne] As Variant, [BiasPointTwo] As Variant ) As FlushConstrain

 

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

You have a spelling mistake here

 

mate3 = asmDoc.ComponentDefinition.Constraints.AddPlushConstraint(face5, face6, 0)

 

see API Help here

 

AssemblyConstraints.AddFlushConstraintEntityOne As Object, EntityTwo As Object, Offset As Variant, [BiasPointOne] As Variant, [BiasPointTwo] As Variant ) As FlushConstrain

 

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

haphanthanhtam.work
Enthusiast
Enthusiast

hi @A.Acheson 
how do you fix it

mate3 = asmDoc.ComponentDefinition.Constraints.AddPlushConstraint(face5, face6, 0)

it's worst
Capture.PNG

 

0 Likes

hi @A.Acheson 
how do you fix it

mate3 = asmDoc.ComponentDefinition.Constraints.AddPlushConstraint(face5, face6, 0)

it's worst
Capture.PNG

 

Message 6 of 7

A.Acheson
Mentor
Mentor
Accepted solution

If you replace the letter "P" with "F" this should fix that method. The error message states you have the wrong method. 

 

Fixed:

mate3 = asmDoc.ComponentDefinition.Constraints.AddFlushConstraint(face5, face6, 0)

 

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

If you replace the letter "P" with "F" this should fix that method. The error message states you have the wrong method. 

 

Fixed:

mate3 = asmDoc.ComponentDefinition.Constraints.AddFlushConstraint(face5, face6, 0)

 

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

haphanthanhtam.work
Enthusiast
Enthusiast

thank you !!!😅

0 Likes

thank you !!!😅

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

Post to forums  

Autodesk Design & Make Report