Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

iLogic - Toggle Constraining, Occurance Numbers/Names

nico
Enthusiast

iLogic - Toggle Constraining, Occurance Numbers/Names

nico
Enthusiast
Enthusiast

Greetings,

 

What I'm trying to build in Inventor 2019; New Toys so experimenting :slightly_smiling_face:

In an assembly enviroment, add 2 different parts, each part has named surfaces 1, 2, 3 for example

Run a Form to Select Part A & Select Part B

Snap Surface 1 from Part A to Surface 1 from Part B

Click again on Part A Then Snap Part B To Surface 2 on Part A

Reverse for Part B

 

The problem I'm running into atm is, since I want to make this a "General" tool

(So having multiple instances of Part A & Part B)

Are the occurance numbers on the parts, how to transfer those along the code

 

More specificly how to move from the Selected "Object" to a "String"

Since the Occurance Name does not have an iProperty value, which is annoying

 

Some Crude Unfinished Code:

SyntaxEditor Code Snippet

Dim Object_A As Object
Dim Object_B As Object

Dim Orientation_A As Integer
Dim Orientation_B As Integer

ThisAssembly.BeginManage("Group 1")
' Section To Add Required Parts/Assembly's ... ' Select The Primary & Secondary Snap Parts Object_A = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select The First Component") Object_B = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select The Second Component") ' Code To Get The Selected Object Into 2 Seperate Strings ' ... ' Loop Trough Each Availible Socket Orientation_A = "1" Orientation_B = "1" ' ... ' Create Named Surface To Named Surface Constraints 'Constraints.AddMate("Mate:1", Object_A, Orientation_A, Object_B, Orientation_B) Constraints.AddMate("Mate:1", "Testblok 2:1", Orientation_A, "Testblok 1:1", Orientation_B) ThisAssembly.EndManage("Group 1") RuleParametersOutput() InventorVb.DocumentUpdate() iLogicVb.UpdateWhenDone = True

  Anyone who has some suggestions on how to do this? :slightly_smiling_face:

 

Kind Regards,

NVD

0 Likes
Reply
927 Views
5 Replies
Replies (5)

MechMachineMan
Advisor
Advisor
Constraints.AddMate("Mate:1", Object_A.Name, Orientation_A, Object_B.Name, Orientation_B)

as outlined in the API under ComponentOccurrence as that is (typically) what object type is returned from your pick command with that specific selection filter.

 

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-DE229A99-9860-4501-AF4C-C671D120A2DB


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes

nico
Enthusiast
Enthusiast

Cheers for the reply,

Object_A.Name inside the Constraints.Addmate() doesn't work and gives and error:

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

But it's easily solved by first defining a string and then inputting that string

 

So far I've split it up into 3 seperate rules, since it's different uses

The Add a Part/Product Rule currently looks like this: (And works like a charm :))

 

Dim Item As String
Dim Item_Unique_ID As String
Dim Item_URL As String
Dim Item_Extensie As String

Dim Offerte_N As String
Dim Materiaal_N As String

Dim oAsmCompDef As AssemblyComponentDefinition
Dim oOccurrence As ComponentOccurrence

If Unique_ID = True Then
	Offerte_N = Offerte_Nummer
	Materiaal_N = Materiaal_Nummer
	Item_Unique_ID = Materiaal_N & " - "
Else
	Offerte_N = ""
	Materiaal_N = ""
	Item_Unique_ID = ""
End If

If Producten = "0000 - Testblok 1" Or Producten = "0000 - Testblok 2" Then
	Item = Product 
	Item_Extensie = ".ipt"
	Item_URL = "C:\$Working Folder\Designs\iLogic Testen\"
	'Item_URL = "C:\$Working Folder\Designs\" & Product & ".ipt"
Else
	Item = Producten & " Configurator" 
	Item_Extensie = ".iam"
	Item_URL = "C:\$Working Folder\Designs\iLogic Testen\"
	'Item_URL = "C:\$Working Folder\Designs\" & Producten & "\20. 3D Designs\" & Producten & " - Configurator.iam"
End If

	oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
	i=0

For Each oOccurrence In oAsmCompDef.Occurrences
	If Left( oOccurrence.Definition.Document.DisplayName,10 ) = Item Then
	   i=i+1
	   oOccurrence.Name = Item & " :"+ CStr(i)
	End If
Next

Dim oProduct = Components.Add(Item_Unique_ID & Item & " :" & (i + "1"), Item & Item_Extensie)
Dim sProduct As String
	sProduct = oProduct.Name

' Unique Product Save - ONLY Top Level with Parameters ! For full copy of all Parts use the Copy command !
	WorkspacePath = ThisDoc.WorkspacePath()
	WorkspacePathLength = Len(WorkspacePath)
	PathOnly = ThisDoc.Path
	DirectoryPath = Strings.Right(PathOnly, PathOnly.Length-WorkspacePathLength)

'Check for the New Save folder and create it if it does not exist
	If(Not System.IO.Directory.Exists(Item_URL)) Then
		System.IO.Directory.CreateDirectory(Item_URL)
	End If

Save = MessageBox.Show("Save This Product?", "Save Product?", MessageBoxButtons.YesNoCancel)

	If Save = vbYes Then
		part = Component.InventorComponent(sProduct)
		doc = ThisApplication.Documents.Open(part.Definition.Document.FullDocumentName, False)
		doc.SaveAs(Item_URL & Item_Unique_ID & Item  & ".iam" , True)
		'doc.Close()
	End If

 

Being able to loop trough and renumber the occurances of identical parts/assemblys is essential

However I also need to do this in my "Constraining Rule" but I can't find a command for this?

 

So final question on this topic, is there a command to run trough all the Relationships and look for an open "Mate" or "Flush" Occurance Number?

0 Likes

MechMachineMan
Advisor
Advisor

I dont think so. 

 

Yay custom solutions!


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes

nico
Enthusiast
Enthusiast

Found a solution, while there might not be a command for this;

if you leave the constraint name empty it auto generates the name + occurance number :slightly_smiling_face:

Constraints.AddMate("", String_A, Orientation_A, String_B, Orientation_B)

The previous posted code still has a few flaws in it but it has gotten a bit big to post it all now

In the case some1 wants to use it, I recommend replacing the  ,10 with a number counted from the new file name

sCharacters = Item_Unique_ID & Item & " :"
		iString_Length = sCharacters.Length
If Left(oOccurrence.Definition.Document.DisplayName,iString_Length) = Item_Unique_ID & Item Then

Back to my constraining code:

Since the "Named Geometry Surfaces" is new in 2019, I'm assuming there is no way yet to automaticly look up / call / list these except for writing the exact name in a rule?

Or automaticly count the number of Surfaces on the part level and put it into a Parameter?

 

0 Likes

Will.Ehrendreich
Contributor
Contributor

THANK YOU SO MUCH for pointing out how to solve this nasty little gotcha about assigning it to a string variable before feeding it in. I couldn't for the life of me figure out why it wasn't taking my occurrence name value and I was starting to go crazy. lol.

 

Thank you, Thank you, Thank you.



 

0 Likes