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: 

iLogic Generator(?) Instead of Configurator

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
gfunnybus
1567 Views, 12 Replies

iLogic Generator(?) Instead of Configurator

My current workflow consists of creating a frame from custom press-fit extrusions. I use a couple common configurations of rails and connectors to generate and endless amount of custom sized frames. I create my frame assembly from library parts and start parts in a new project. When a new size is required I save copies of the changed parts and assembly to a specific syntax and replace each part manually. This is on a project to project basis because the components that are added to the frame assemblies are always unique. 

 

So far I have determined that skeletal modeling and frame generator are not what I am looking for. I have also been leaning away from iAssemblies because from what I have gained so far is that they are strictly limited to a table.

 

What I would like to achieve is an iLogic assembly within a library folder (or start parts (?) ) folder. This assembly could then be copied into the current project folder. On open, the assembly would prompt the user asking to generate a new frame definition. If yes, you would be prompted to input the name of the new assembly that is to be created. After naming, you would be prompted to define the parameters (a mixture of length dimensions, multivalues for finish, and true/false values for suppressing components). After defining the parameters, the rule would check for components effected by the changes, save copies of them according to a syntax (ex: RAIL, 1 X 2 X [changed parameter], FINISH: [changed finish].iptupdate the new ones to the proper size, and replace them in the new assembly. Maybe this could be solved by simply editing the way "place iLogic component" works?

 

I will attach one of my configurations for reference.

 

Don't hate too hard, first post, and began teaching myself iLogic mid last week 🙂

12 REPLIES 12
Message 2 of 13
rjay75
in reply to: gfunnybus

Hello,

 

This is actually how I use iLogic. Rather than make configurations I have generators. The typical structure of the project I use is in a folder all the template parts and assemblies that will be used. I have a basic set of tenants I use to make this work.

1. I will usually have a master assembly that is the starting point of the generator.

2. To avoid circular dependancy's all parts and assemblies are linked/derived off the base file.

3. The base file has no dependencies of its own.

4. Any shared parameters or sketches links are shared through the base file. (Some parts can be derived of each other.) Parts are never derived off an assembly.

5. In my base file I have a configuration rule that displays the configuration for the design.

6. Mix of internal and external rules. Any rule that uses more than one part, creates new parts, or can be applied to multiple parts are external.

7. Rules that only manipulate parameters and features in a single part can be internal to that part.

8. Carefully decide what rules run automatically and which ones won't. For me most won't run automatically.

9. In my main generation rule I verify the configuration in the base file then begin calculating and numbering (or assigning names) to all the parts that must be created.

10. Each part is created from a template that has a derived part to the template of the base file. When the part is created the derived files are replaced to point to the current design's base file. Each part has an internal generate rule that will update itself and call any other external rules it needs

11. The generated parts are placed in either a subassembly or main assembly and constained using skelatal modeling techniques. (Alot of the parts use the same base sketches on the base file.) Or are positioned using iMates, or named planes, axis, points.

12. Depending on the design they can be updated easily by just modifying the base configuration, and/or generating or removing specific parts.

 

The most difficult part of this process is having a flexible but strict naming structure for a design that can be programattically assigned.

 

Message 3 of 13
gfunnybus
in reply to: rjay75

Thanks, glad to see I'm not alone working this way. I don't mean to steal your secrets or anything, but I'd like to check out a sample of your external rule(s)/code if you don't mind. I can IF and FOR competently, but i'm not great at assigning variable functions. I am assuming the external rule is what you use to save copies (create new parts) and replace within your template assembly?

Message 4 of 13
rjay75
in reply to: gfunnybus

Attached is part of a sample of one of my assembly generation rules. It won't run as is but has enough code to give you an idea of what I'm doing. It assembles a part with an arbitrary amount of parts that are specified from input.

 

Also I would recommend starting by creating your templates and completely walking through and outline assembling the assembly manually before trying to script it. This will help you see where special decisions have to be made and finding where you can share information.

 

Note: There's a lot of lines with objects that start with (ilx), that is a custom utility library that has simplified and special functions for working with documents. Everything those functions are doing can be done using the regular Inventor API. It just mae take more lines of code.

Message 5 of 13
gfunnybus
in reply to: rjay75

If isNew Or (Not skipFiles) Then
	'Get New Plate Part File
	ilxSectIBP = ilx.GetiLXDocument(sectIBPFile)
	ilx.ConsoleWrite("Updating:  " + sectIBPFile)
	'Set The Plate Number
	ilxSectIBP.GetParameter("PlateNo").Value = CDbl(i)
	'Replace the Base Reference & Update the Part
	ilxSectIBP.ReplacedDerivedReference(plateBase)
	'Replace the inner cutout derived reference
	ilxSectIBP.ReplacedDerivedReference(plateICO, innerCutOut)
	ilxSectIBP.Update()
	'Regenerate the Part to the new updated Base And Save.
	ilxSectIBP.RunExternalRule("InnerP.Generate")
	ilxSectIBP.Update()
	isNew = False
End If

 I believe this is what I am looking to accomplish. I would like to know how to code this without the custom ilx library.

 

Also, props for magic:

'Magically figure out the part numbering.

 Thanks

Message 6 of 13
rjay75
in reply to: gfunnybus

Here's the code snippet you highlighted not using the library. More code is needed for looping through the derived parts to find a specific derived part to replace, or just replace the first in the list.

 

'Check and see if part file exists, if not create it.
If (Not SysIO.File.Exists(sectIBPFile)) Then
    ilx.ConsoleWrite("Creating: " + sectIBPFile)
    sDoc = ThisApplication.Documents.Open(tempIBP, False)
    sDoc.SaveAs(sectIBPFile, True)
    sDoc.ReleaseReference()
    sDoc.Close()
    isNew = True
End If
		
If isNew Or (Not skipFiles) Then
    'Open the newly created part file
    Dim ilxSectIBPAs PartDocument
    ilxSectIBP = ThisApplication.Documents.Open(sectIBPFile)
    'Set any parameter values
    iLogicVb.Automation.ParamValue(ilxSectIBP, "PlateNo", CDbl(i))
    'Replace the Base Reference & Update the Part
    'Replace the inner cutout derived reference
    'Cycle through the DerivedPartComponents
    '(ilxSectIBP.ComponentDefinition.ReferenceComponents.DerivedPartComponents)
    'ReplaceReference on the ReferencedFileDescriptor of the desired derived parts.
    ilxSectIBP.Update()
    'Regenerate the Part to the new updated Base And Save.
    iLogicVb.Automation.RunExternalRule(ilxSectIBP, "InnerP.Generate")
    ilxSectIBP.Update()
    isNew = False
End If

 The most important thing is a normal iLogic assembly does everything in the context of an assembly and its components. This generation method ignores that context. So to run rules on documents outside the current document's context iLogicVb.Automation is used to run iLogic function given a specific document as the context. Other functions such as the Update, Open, document creation functions are just using the Inventor API.

Message 7 of 13
gfunnybus
in reply to: rjay75

I came up with this simplified outline (below) of what I would like to be able to do. The configurator I attached in the OP runs through all of this, but I am totally lost as to how I would go about coding the external rule. All help would be GREATLY appreciated. Being able to grab any of my config assemblies and use them to generate like this would be an unbelievable time saver. Thanks

 

open library assembly: "FRAME.iam"

trigger/run rule

show ilogic form in library assembly

prompt for file path of copy to be made

input desired parameters for copy
	WIDTH -> 48
	DEPTH -> 24
	HEIGHT -> 12
differ exporting parameters to library components (should always remain static/default)

prompt to generate

if yes

	copy assembly with name related to its parameters
	"FRAME.iam" (library location) -> "FRAME, W_048.0000 X D_024.0000 X H_012.0000.iam" (new location)

	copy each part with name related to the parameter that effects it
	"RAIL, WIDTH.ipt" (library location) -> "RAIL, WIDTH, 048.0000.ipt" (new location)
	"RAIL, DEPTH.ipt" (library location) -> "RAIL, DEPTH, 024.0000.ipt" (new location)
	"LEG.ipt" (library location) -> "LEG, 012.0000.ipt" (new location)
	export parameters to copied parts
	update copied parts

	open copied assembly

	component>replace all in "FRAME, W_048.0000 X D_024.0000 X H_012.0000.iam"
	"RAIL, WIDTH.ipt" with "RAIL, WIDTH, 048.0000.ipt"
	"RAIL, DEPTH.ipt" with "RAIL, DEPTH, 024.0000.ipt"
	"LEG.ipt" with "LEG, 012.0000.ipt"
	update copied assembly
	save copied assembly
	close copied assembly

	return to library assembly

	prompt to generate new size
	show ilogic form in library assembly

else

	show ilogic form in library assembly

end if

 

Message 8 of 13
gfunnybus
in reply to: gfunnybus

 

Made progress, but now I am having trouble pushing iProperties and parameters to the components (Else area of If statement). Any ideas?

 

oNumRailWidth1 = ThisDoc.Document.ComponentDefinition.Occurrences.Item(11)
oNumRailWidth2 = ThisDoc.Document.ComponentDefinition.Occurrences.Item(12)

Dim oFilePath As String = "<file path>"

Dim oRailWidth As Double = WIDTH - 3

'old name
Dim oOldRailWidth As String = "RAIL, WIDTH"

'new name
Dim oNewRailWidth As String = oOldRailWidth & " " & oRailWidth.ToString("00.0000") & ".ipt"

Try
	If System.IO.File.Exists(oNewRailWidth)
		ThisApplication.StatusBarText = "Replacing: " & oOldRailWidth & ".ipt" & " with " & oNewRailWidth
		oNumRailWidth1.Replace(oFilePath & oNewRailWidth, False)
		oNumRailWidth2.Replace(oFilePath & oNewRailWidth, False)
	Else
		ThisApplication.StatusBarText = "Generating: " & oNewRailWidth
		invDoc = ThisApplication.Documents.Open(oFilePath & oOldRailWidth & ".ipt", False)
		invDoc.saveas(oFilePath & oNewRailWidth, False)
		
		'push oRailWidth to invDoc "LENGTH" parameter
		'Parameter("LENGTH") = oRailWidth
		'push oOldRailWidth to "Project, Part Number" iProp
		'iProperties.Value("Project", "Part Number") = oOldRailWidth

		invDoc.Close
		ThisApplication.StatusBarText = "Replacing: " & oOldRailWidth & ".ipt" & " with " & oNewRailWidth
		oNumRailWidth1.Replace(oFilePath & oNewRailWidth, False)
		oNumRailWidth2.Replace(oFilePath & oNewRailWidth, False)
		InventorVb.DocumentUpdate()
	End If
Catch
	ThisApplication.StatusBarText = "):"
	MessageBox.Show("Failed To Generate")
End Try

 Thanks!

 

Message 9 of 13
rjay75
in reply to: gfunnybus

Some notes and ideas on this. First remember the context (document) the rule is running in. Every time you reference/modify a paramater or iProperty think, are you modifying a parameter or iProperty in the document running the rule, or a different document. (The reason I say document running a rule and not the ActiveDocuement is they will not always be the same. (And with generators and configurators often not.

 

 

auto = iLogicVb.Automation

 

'You are selecting specific occurrences by index. They may not always be at that position.

oNumRailWidth1 = ThisDoc.Document.ComponentDefinition.Occurrences.Item(11)
oNumRailWidth2 = ThisDoc.Document.ComponentDefinition.Occurrences.Item(12)

 

Dim oFilePath As String = "<file path>"

Dim oRailWidth As Double = WIDTH - 3 'What file holds the WIDTH parameter

 

'old name
Dim oOldRailWidth As String = "RAIL, WIDTH"

'new name
Dim oNewRailWidth As String = oOldRailWidth & " " & oRailWidth.ToString("00.0000") & ".ipt"

 

Try
   If System.IO.File.Exists(oNewRailWidth)
      ThisApplication.StatusBarText = "Replacing: " & oOldRailWidth & ".ipt" & " with " & oNewRailWidth
      oNumRailWidth1.Replace(oFilePath & oNewRailWidth, False)
      oNumRailWidth2.Replace(oFilePath & oNewRailWidth, False)
   Else
      ThisApplication.StatusBarText = "Generating: " & oNewRailWidth
      invDoc = ThisApplication.Documents.Open(oFilePath & oOldRailWidth & ".ipt", False)

 

       'Get new saved document
      Dim newDoc As Document = invDoc.saveas(oFilePath & oNewRailWidth, False)
      invDoc.Close


      'push oRailWidth to document newDoc "LENGTH" parameter
      auto.ParamValue(newDoc, "LENGTH") = oRailWidth
     

      'push oOldRailWidth to "Project, Part Number" iProp
      'iProperties.Value("Project", "Part Number") = oOldRailWidth

 

      newDoc.Save()

      newDoc.Close()

 

      ThisApplication.StatusBarText = "Replacing: " & oOldRailWidth & ".ipt" & " with " & oNewRailWidth
      oNumRailWidth1.Replace(oFilePath & oNewRailWidth, False)
      oNumRailWidth2.Replace(oFilePath & oNewRailWidth, False)
      InventorVb.DocumentUpdate()
   End If
Catch
ThisApplication.StatusBarText = "):"
MessageBox.Show("Failed To Generate")
End Try

 

iProperties are trickier to get to. Will look at that later.

Message 10 of 13
gfunnybus
in reply to: rjay75

Thanks! So close... I have been attempting to find the right way to send the parameters to "document outside of the rule" all day. I grasp the idea of active vs. running rule, I just lack the coding experience/know how. I made the changes you suggested. The rule will run without error, however, the parameters don't seem to making it to the models, and if i use the newDoc.Save() and or newDoc.Close() the parts will not generate at all (due to the "catch" of the "try").

 

EDIT: Uploaded latest assembly w/code.

 

iTrigger launches form, changes to form parameters trigger rule. At the moment parts are generated but parameters are not applied to generated parts (commented out). The file path will need to be edited at the top. 

 

I have to appologize, the generator kicks out a ton of parts and can make testing the code unwieldy 😕

 

Thanks!

Message 11 of 13
gfunnybus
in reply to: rjay75

Ok, I've exhausted my research and trail & error abilities attempting to get this code to run properly. By using MsgBox's between each line of code I've determined the failure is at auto.ParamValue(newDoc, "LENGTH") = oRailWidth. oRailWidth is a double, so I doubt it is a type mismatch. This is how I understand it as it stands:

 

access the iLogic automation interface

auto = iLogicVb.Automation

get "old" saved document and open without generating graphics

invDoc = ThisApplication.Documents.Open(oFilePath & oOldRailWidth & ".ipt", False)

define "new" document as the "save copy as" of the old document

Dim newDoc As Document = invDoc.saveas(oFilePath & oNewRailWidth, False)

close the "old" document

invDoc.Close

access parameters of the "new" document through the inventor automation interface and assign it the value of oRailWidth

auto.ParamValue(newDoc, "LENGTH") = oRailWidth

save the "new" document

newDoc.Save()

close the "new" document

newDoc.Close()

 

Am I missing something here? Maybe the "new" document needs to be defined as ThisDoc.Document? Maybe something like ThisDoc.Parameter("LENGTH") = oRailWidth needs to follow? I have tried a lot of combinations to no avail. Help very much appreciated.

 

As far as pushing iProperties, that's not critical at this point, I can just add that to a rule within the part.

 

Thanks!

 

 

 

Message 12 of 13
rjay75
in reply to: gfunnybus

Just saw an error didn't see before. SaveAs doesn't return the new document. You have to explictly open it.

 

access the iLogic automation interface

auto = iLogicVb.Automation

get "old" saved document and open without generating graphics

invDoc = ThisApplication.Documents.Open(oFilePath & oOldRailWidth & ".ipt", False)

"save copy as" of the old document

invDoc.saveas(oFilePath & oNewRailWidth, False)

close the "old" document

invDoc.Close

 

Define and open new document

Dim newDoc As Document = ThisApplication.Documents.Open(oFilePath & oNewRailWidth, False)

 

access parameters of the "new" document through the inventor automation interface and assign it the value of oRailWidth

auto.ParamValue(newDoc, "LENGTH") = oRailWidth

 

save the "new" document

newDoc.Save()

close the "new" document

newDoc.Close()

Message 13 of 13
gfunnybus
in reply to: rjay75

Champion.

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

Post to forums  

Autodesk Design & Make Report