Using IV2013
1.) I found a post that says that iLogic doesn't support wildcards. Are there any workarounds for this? For example, say I want a rule to suppress all hex bolts regardless of size in an assembly. Assuming all hex bolts will have the term "HEX BOLT" in the name, can such a rule be made?
2.) I was wondering if iLogic can access assembly (browser) folders to manipulate all files under it. For example, I have an assembly folder named "Hardware". Can iLogic access that folder by name?
3.) When an equation driven parameter gets pushed between files via an iLogic rule only the value is pushed instead of the equasion. For example, an IAM and IPT has the parameter with equation "PlaneElevation=Height/2". With iLogic this value is to be pushed from the IAM to IPT but if I change the IAM equation to "Height/4" then the IPT's "PlaneElevation" value loses the equation and is replaced with only the numerical value. What I'd like is the IPT's parameter to also read "Height/4".
Thanks.
MechMan
Solved! Go to Solution.
Solved by cwhetten. Go to Solution.
Ok, here are some answers for you.
1) I don't know whether or not iLogic (or even VB.net) can use wildcards. But assuming it can't, you can work around it by using something similar to this:
'Get the set of occurrences in this assembly document oOccurrences = ThisDoc.Document.ComponentDefinition.Occurrences 'Cycle through each component in the set For Each oComp As ComponentOccurrence In oOccurrences 'Get the browser name of the component oCompName = oComp.Name 'Check if the desired bit of text is in the component's name If InStr(oCompName, "HEX BOLT") > 0 Then If oComp.Suppressed Then 'If the component is already suppressed, do whatever you want to it here Else 'If the component is NOT already suppressed, do whatever you want to it here End If End If Next
The above code checks the browser name for each component in your assembly to see if it has "HEX BOLT" in it somewhere. This bit of text is case sensitive, so it has to match EXACTLY. If your components' names vary slightly, you will have to account for that variation.
2) Here is some example code that accesses a browser folder and cycles through each object in the folder (in this example, it toggles the suppression state):
'Get the normal assembly browser pane object oPane = ThisDoc.Document.BrowserPanes.Item("AmBrowserArrangement") 'Get the browser folder object oFolder = oPane.TopNode.BrowserFolders.Item("Hardware") 'Get the set of nodes in the folder oFolderNodes = oFolder.BrowserNode.BrowserNodes 'Cycle through each browser node in the folder For Each oNode As BrowserNode In oFolderNodes 'Get the actual object that the node represents, in this case, assembly components oComp = oNode.NativeObject 'Do whatever you want to the component. In this example, toggle the suppression state If oComp.Suppressed Then oComp.Unsuppress Else oComp.Suppress End If Next
3) Manipulating the parameter expression is much easier than I thought it would be. Below is some code that does what you describe:
p = PlaneElevation 'This line doesn't actually do anything, but it makes sure this rule fires when PlaneElevation is changed 'Use Parameter.Param to get the actual parameter object. This is used below to access the expressions of the parameters. oAsmParam = Parameter.Param("PlaneElevation") oCompParam = Parameter.Param("SubComponent Name", "PlaneElevation") 'You probably want to pass the value of the Height parameter, since PlaneElevation depends on it Parameter("SubComponent Name", "Height") = Height 'The following line sets the expression of the component paremeter to equal the expression of the assembly parameter. oCompParam.Expression = oAsmParam.Expression
Post back if you have any questions.
Cameron Whetten
Inventor 2014
Please click "Accept as Solution" if this response answers your question.
Great Answers Cameron! You even defined everything very well for a code newbie such as myself.
I wouldn't mind hearing from Adesk or someone whether my questions are actual iLogic limitations.
MechMan
This is amazing stuff, Check out how i expounded on it. This code below is a External Rule. Basically i needed to turn off visibility of a part that can be a different part name every single time. The way i target it is in the iproperties. If iproperties is this, then do this. This is soo easy.
Dim openDoc As Document openDoc = ThisDoc.Document Dim docFile As Document If openDoc.DocumentType = 12291 Then For Each docFile In openDoc.AllReferencedDocuments If docFile.DocumentType = 12290 Then Dim FNamePos As Long FNamePos = InStrRev(docFile.FullFileName, "\", -1) Dim docFName As String docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos) If iProperties.Value(docFName, "Project", "Description")="ENDPLATE" Then ShortName = Left(docFName, Len(docFName) - 4) If Component.Visible(ShortName & ":2") = True Then Component.Visible(ShortName & ":2") = False Component.Visible(ShortName & ":1") = False Else If Component.Visible(ShortName & ":2") = False Then Component.Visible(ShortName & ":2") = True Component.Visible(ShortName & ":1") = True End If End If 'rebuild/refresh document to see results ThisDoc.Document.Rebuild() End If End If Next Else MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation) End If
this code is suppressing features in a .ipt:
Dim openDoc As Document openDoc = ThisDoc.Document Dim docFile As Document If openDoc.DocumentType = 12291 Then For Each docFile In openDoc.AllReferencedDocuments If docFile.DocumentType = 12290 Then Dim FNamePos As Long FNamePos = InStrRev(docFile.FullFileName, "\", -1) Dim docFName As String docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos) If iProperties.Value(docFName, "Project", "Description")="BASEPLATE" Then 'iProperties.Value(docFName, "Project", "Description") = iProperties.Value(docFName, "Custom", "DISPLAY_NAME") 'iLogicVb.RunRule(docFName, "GROUT HOLES") 'ThisDoc.Document.Rebuild() If Feature.IsActive(docFName, "GROUT HOLES (REFERENCE ONLY)") = True Then Feature.IsActive(docFName, "GROUT HOLES (REFERENCE ONLY)") = False Else If Feature.IsActive(docFName, "GROUT HOLES (REFERENCE ONLY)") = False Then Feature.IsActive(docFName, "GROUT HOLES (REFERENCE ONLY)") = True End If End If 'rebuild/refresh document to see results ThisDoc.Document.Rebuild() End If End If Next Else MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation) End If
this code is running a ilogic rule in a part:
Dim openDoc As Document openDoc = ThisDoc.Document Dim docFile As Document If openDoc.DocumentType = 12291 Then For Each docFile In openDoc.AllReferencedDocuments If docFile.DocumentType = 12290 Then Dim FNamePos As Long FNamePos = InStrRev(docFile.FullFileName, "\", -1) Dim docFName As String docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos) If iProperties.Value(docFName, "Project", "Description")="BASEPLATE" Then iLogicVb.RunRule(docFName, "OPEN FORM") ThisDoc.Document.Rebuild() End If End If Next Else MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation) End If
Hello Cameron
Thanks for the post on suppressing folder contents - whats needed to iterate the same process through all sub assemblies?
Regards
Andrew