ISSUE WITH iLOGIC AND AND MATES

ISSUE WITH iLOGIC AND AND MATES

tmathieson
Advocate Advocate
579 Views
6 Replies
Message 1 of 7

ISSUE WITH iLOGIC AND AND MATES

tmathieson
Advocate
Advocate

Hi All,

 

i am having a bit of an issue with the AddMate and AddInsert snippets in iLogic.  i am writing a rule that will add components to an assembly (no issue).  once i bring the component in, i want to mate it to features in the proceeding component.  if i use the actual names  of the parts they will mate as they should.  however, i want to cycle thru, setting  my new part name to a variable (LAST_PLATE), and then add the mate.  As we could be adding from 3-12 components, we  need to have this "LAST_PLATE"  change to the last component added. as soon as i place  the variable into the code instead of the actual name, it craps out.. is there something i'm missing in parsing these variables in the addmate command? i'included the snippet here, and also a screen dump of the ilogic window and assembly tree. i've hilited in RED the line i'm having issues with...

 

For Each wrd In Words
	PLATE_NAME = "PLATE-" & (i + 1)
	Logger.Debug(PLATE_NAME)
	MessageBox.Show(PLATE_NAME, "PLATE #")

	Dim componentA = Components.Add(PLATE_NAME, "SC-H-2R-P1.ipt", position := Nothing, grounded := GROUND, visible := True, appearance := Nothing)
	If i = 0 Then
		LAST_PLATE = PLATE_NAME
		GROUND=False
		i = i + 1
		GoTo JUMP_NEXT
	End If
	LAST_PLATE = PLATE_NAME
	MessageBox.Show(LAST_PLATE, "LAST PLATE")
	Constraints.AddMate("Mate:1", "PLATE-2", "CH-4", "PLATE-1", "CH-3",
                        e1InferredType := InferredTypeEnum.kInferredLine,
                        e2InferredType := InferredTypeEnum.kInferredLine,
                        solutionType := MateConstraintSolutionTypeEnum.kOpposedSolutionType)
    
	Constraints.AddInsert("", LAST_PLATE, "PEAK-2", PLATE_NAME, "PEAK-1",
                      axesOpposed := True, distance := 0.0, lockRotation := False, biasPoint1 := Nothing, biasPoint2 := Nothing)
	'Constraints.AddMate("Mate1", "PLATE-1", "CH-2", "PLATE-2", "CH-1",
 '                   offset := 0.0, e1InferredType := InferredTypeEnum.kNoInference, e2InferredType := InferredTypeEnum.kNoInference,
  '                  solutionType := MateConstraintSolutionTypeEnum.kNoSolutionType,
   '                 biasPoint1 := Nothing, biasPoint2 := Nothing)
	'Constraints.AddInsert("", "PLATE-1", "CH-2", "PLATE-2", "CH-1",
                     ' axesOpposed := False, distance := 0.0, lockRotation := False, biasPoint1 := Nothing, biasPoint2 := Nothing)
	Constraints.AddInsert("", "PLATE-1", "PEAK-2", "PLATE-2", "PEAK-1",
                      axesOpposed := True, distance := 0.0, lockRotation := False, biasPoint1 := Nothing, biasPoint2 := Nothing)
	i = i + 1
	Logger.Debug("I = "& i)
	JUMP_NEXT:
Next

thanks in advance for any insight!


 
 

 

0 Likes
Accepted solutions (1)
580 Views
6 Replies
Replies (6)
Message 2 of 7

Ralf_Krieg
Advisor
Advisor

Hello

 

You set LAST_PLATE = PLATE_NAME before adding mates. Try setting it after.


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 3 of 7

tmathieson
Advocate
Advocate

hi, and thanks for your response.  the issue i am having is that i want to insert some components and mate them to the previous component.  i cannot use the actual component name, as it will vary... there could be up to 15 part"x" , and part "x"  could be one of 4 different parts, so i can't hard code it (i don't think...). 

 

the basic loop is...

- insert part 1, grounded, set to variable  "Last Plate"

- insert part 2, mate to Last Plate, set to variable  "Last Plate"

- insert part 3, mate to Last Plate, set to variable  "Last Plate"

- etc, etc

 

i have tried a couple different ways of getting the name into the variable, but no success.  unless it is hard coded, "PLATE-1", "PLATE-2", like shown below in GREEN, it kicks out. what i hoping for  is to find a way to make the code in BLUE work.  it seems like as soon as i try a variable instead of the actual name, even after adding mates, poof...

 

For Each wrd In Words
	PLATE_NAME = "PLATE-" & (i + 1)
	Logger.Debug(PLATE_NAME)
	'MessageBox.Show(PLATE_NAME, "PLATE #")
	If i = 0 Then
		componentB = Components.Add(PLATE_NAME, "SC-H-2R-P1.ipt", position := Nothing, grounded := GROUND, visible := True, appearance := Nothing)
		LAST_PLATE = PLATE_NAME
		GROUND=False
		i = i + 1
		GoTo JUMP_NEXT
	Else If	 i = UBound(Words) Then ' LAST PLATE, ADD HAUNCH
		componentB = Components.Add(PLATE_NAME, "SC-H-2R-P1.ipt", position := Nothing, grounded := GROUND, visible := True, appearance := Nothing)
		i = i + 1
		GoTo JUMP_NEXT
	End If
		InventorVb.DocumentUpdate()
	'MessageBox.Show(LAST_PLATE, "LAST PLATE today")
componentA = Components.Add(PLATE_NAME, "SC-C-P2.ipt", position := Nothing, grounded := False, visible := True, appearance := Nothing)

oOcc = Component.InventorComponent(last_plate)

'get the file path from the component occurrence 
oDoc_Name = oOcc.Definition.Document.fullfileName
'MessageBox.Show(oDoc_Name, "help")
LAST_P = Chr(34) & LAST_PLATE & Chr(34)
NEW_P = Chr(34) & PLATE_NAME & Chr(34)
MessageBox.Show(LAST_P &"   " & NEW_P, "ALLL")

	'Constraints.AddMate("", NEW_P, "CH-1", LAST_P, "CH-2",e1InferredType := InferredTypeEnum.kInferredLine,e2InferredType := InferredTypeEnum.kInferredLine,solutionType := MateConstraintSolutionTypeEnum.kOpposedSolutionType)
	Constraints.AddMate("", "PLATE-2", "CH-4", "PLATE-1", "CH-3",e1InferredType := InferredTypeEnum.kInferredLine,e2InferredType := InferredTypeEnum.kInferredLine,solutionType := MateConstraintSolutionTypeEnum.kOpposedSolutionType)
	Constraints.AddMate("", "PLATE-2", "PEAK-1", "PLATE-1","PEAK-2",e1InferredType := InferredTypeEnum.kInferredLine,e2InferredType := InferredTypeEnum.kInferredLine,
                                            solutionType := MateConstraintSolutionTypeEnum.kAlignedSolutionType)             
    InventorVb.DocumentUpdate()
	Constraints.AddInsert("", "PLATE-1", "PEAK-2", "PLATE-2", "PEAK-1",axesOpposed := False, distance := 0.0, lockRotation := False, biasPoint1 := Nothing, biasPoint2 := Nothing)
	LAST_PLATE = PLATE_NAME
	i = i + 1
	Logger.Debug("I = "& i)
	JUMP_NEXT:

 thanks again, and any suggestions greatly appreciated!!

0 Likes
Message 4 of 7

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @tmathieson 

 

Here is one way to do this.

See the attached Inventor 2020 example files. ( Plates.zip )

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

Dim oPlateFile = "Plate100.ipt"
Dim oPlatePrefix = "Plate:"

Dim oDoc As AssemblyDocument
oDoc = ThisDoc.Document

j = 0
'count existing plates, if any
For Each oOcc In oDoc.ComponentDefinition.Occurrences
	If oOcc.name.contains(oPlatePrefix) Then
		j = j + 1
	End If
Next

Dim oPlateCount As Integer
Try
	oPlateCount = InputBox("Current plate count: " & j _
					& vbLf & vbLf & "Enter plate new count", "iLogic", j + 1)
Catch
	Return
End Try

If oPlateCount < j Then
	For Each oOcc In oDoc.ComponentDefinition.Occurrences
		If oOcc.name.contains(oPlatePrefix) Then
			oSplit = Split(oOcc.name, ":")
			If oSplit(1) > oPlateCount Then 
				oOcc.delete
			End If
		End If
	Next
End If


For i = 1 To oPlateCount

	If i = 1 Then oGrounded = True: Else oGrounded = False

	Dim oNewPlate = Components.Add(oPlatePrefix & i, oPlateFile, , oGrounded)

	If i = 1 Then GoTo SkipInserts
	Dim oPreviousPlate = Component.InventorComponent(oPlatePrefix & i - 1)

	'constrian 
	Constraints.AddInsert("PlateInsert:A" & i,
	oPreviousPlate.Name, "InsertEdge1",
	oNewPlate, "InsertEdge3",
	axesOpposed := True)

	Constraints.AddInsert("PlateInsert:B" & i,
	oPreviousPlate.Name, "InsertEdge2",
	oNewPlate, "InsertEdge4",
	axesOpposed := True)

	SkipInserts :
Next
InventorVb.DocumentUpdate()

 

EESignature

Message 5 of 7

Ralf_Krieg
Advisor
Advisor

Hello

 

I can not test your code, but why adding this double quotes here?

 

LAST_P = Chr(34) & LAST_PLATE & Chr(34)
NEW_P = Chr(34) & PLATE_NAME & Chr(34)

 

 I think this work without these extra quotes

 

LAST_P = LAST_PLATE
NEW_P = PLATE_NAME

 

or use the variables direct

 

Constraints.AddMate("", PLATE_NAME, "CH-1", LAST_PLATE, "CH-2",e1InferredType := InferredTypeEnum.kInferredLine,e2InferredType := InferredTypeEnum.kInferredLine,solutionType := MateConstraintSolutionTypeEnum.kOpposedSolutionType)

 

 

What means kicks out? Is there any message? I assume the EntityNames are correct?


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 6 of 7

tmathieson
Advocate
Advocate

Hi @Curtis_Waguespack ,  Thanks so much!!  with a little tweaking of your code to match my variables, mission accomplished!! once again you have gotten me out of a corner!  users like yourself and @Ralf_Krieg  and others really make tse forums work.  hopefully, someday i will be able to help out others as I have been helped out.

 

on to the next step in development (with this Forum not too far away! :^}).  again, thanks so much to you and @Ralf_Krieg for taking the time to look at this.  have a great day!!

Message 7 of 7

tmathieson
Advocate
Advocate

Hi @Ralf_Krieg , thanks for replying to this thread.  yes, i agree  that the code  shown here should of worked,

 

LAST_P = LAST_PLATE
NEW_P = PLATE_NAME

 but if you review my first post, that was the issue i was having, that "LAST_PLATE" or "PLATE_NAME" would not parse correctly into the AddMate snippet.. it would keep kicking out.  when i popped up a message box with just LAST_PLATE or NEW_PLATE in it  i would see on the letters, i.e. PLATE-1, PLATE-2, etc, no quotes so i thought maybe by adding the quotations marks it would parse right (it didn't).  the screen shot below shows what how my variables looked after adding the quotes....

 

Still not sure why it wouldn't parse correctly, but when i adapted Curtis code to mine, i had to change the prefix from "PLATE-"  to "PLATE:"...  not sure why...

 

anyways, as mentioned in my reply to Curtis, i have it working, so forward we go!!

 

thanks again for you attention to this.  have a good one!!

0 Likes