Hello,
I am hoping iLogic or some other method can help me solve this issue. This is not really an issue, but more a time consuming process that I would like to automate. I have created a very simple yet effective tool for starting a new manifold assembly using iLogic. The rules and windows essentially fill out the size of the block, material type, description, project and part number.
Below I have a hydraulic manifold I have designed and from that I created the final .ipt of the internals. The way I did this (which may not be the best method) was to create a second .ipt matching the LxWxH of the original manifold, next I inserted and aligned both into another .iam file, lastly I derived a third .ipt from a subtraction resulting in the third image below. This is a bit time consuming to create, but has been very helpful in error checking our designs. I would like to see if iLogic is capable of allowing me to automate this so we can easily create these internal flowpath .ipt's for every manifold we design. Is there a resource or something similar someone else has done that could point me in the right direction?
Thanks for any help you may be able to furnish, I really appreciate it.
Darek Davis
Solved! Go to Solution.
Solved by Vladimir.Ananyev. Go to Solution.
Good case.
iLogic “can” automate this procedure via direct calls to Inventor API objects. My sample rule implements slightly modified method. It wasn’t tested much (see screenshot).
Please copy this code into the rule in your manifold part and run the rule.
Hope it will help you as a good start point for your own “magic” rule.
IMHO for this task it is better to use Inventor API and any .NET developing tool (VB, C#,…). Really I developed and tested this code in the form of VB.NET EXE application (because Visual Studio has excellent debugger) and only then copied resulting code into iLogic rule with very little modifications.
Sub Main 'Step 0: reference to active part Dim oSourcePartDoc As PartDocument _ = CType(ThisApplication.ActiveDocument, PartDocument) ' Dim oSourcePartDoc As PartDocument = CType(ThisDoc.Document, PartDocument) 'Step 1: create outer body Body2 using shrinkwrap Dim oOuterPartDoc As PartDocument = ShrinkWrap(oSourcePartDoc) 'Step 2: create new part derived source and shrinkwrap bodies ' and subtract Body1 (source) from Body2 (outer) Dim oResultDoc As PartDocument = SubtractPart(oSourcePartDoc, oOuterPartDoc) oResultDoc.Views.Add() ThisApplication.SilentOperation = True Call oOuterPartDoc.Save() Call oOuterPartDoc.Close() ThisApplication.SilentOperation = False Beep() End Sub 'Main Function ShrinkWrap(ByVal oSourcePartDoc As PartDocument) As PartDocument Dim oTG As TransientGeometry = ThisApplication.TransientGeometry 'active project workspace path Dim oProjectManager As DesignProjectManager = ThisApplication.DesignProjectManager Dim oActiveDesignProject As DesignProject = oProjectManager.ActiveDesignProject Dim WorkspacePath As String = oActiveDesignProject.WorkspacePath ' Create new assembly document Dim oAssyDoc As AssemblyDocument = CType(ThisApplication.Documents _ .Add(DocumentTypeEnum.kAssemblyDocumentObject, , False), _ AssemblyDocument) 'assembly definition Dim oAssyDef As AssemblyComponentDefinition = oAssyDoc.ComponentDefinition 'Add the source component Dim oMatrix As Matrix = oTG.CreateMatrix Dim oOcc As ComponentOccurrence = oAssyDef.Occurrences _ .AddByComponentDefinition(CType( _ oSourcePartDoc.ComponentDefinition, _ ComponentDefinition), oMatrix) oOcc.Name = "Manifold" ' create filename for this assembly and save it Dim AssyFilename As String = WorkspacePath & "\TemporaryAssy.iam" ' MsgBox(AssyFilename) ThisApplication.SilentOperation = True oAssyDoc.SaveAs(AssyFilename, False) ThisApplication.SilentOperation = False ' MsgBox("Saved") ' Create a new part document that will be the shrinkwrap substitute Dim oPartDoc As PartDocument = CType(ThisApplication.Documents _ .Add(DocumentTypeEnum.kPartDocumentObject, , False), _ PartDocument) Dim oPartDef As PartComponentDefinition = oPartDoc.ComponentDefinition Dim oDerivedAssemblyDef As DerivedAssemblyDefinition _ = oPartDef.ReferenceComponents.DerivedAssemblyComponents _ .CreateDefinition(oAssyDoc.FullDocumentName) ' Set various shrinkwrap related options oDerivedAssemblyDef.DeriveStyle _ = DerivedComponentStyleEnum.kDeriveAsSingleBodyNoSeams oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions _ = DerivedComponentOptionEnum.kDerivedExcludeAll oDerivedAssemblyDef.IncludeAllTopLevelParameters _ = DerivedComponentOptionEnum.kDerivedExcludeAll oDerivedAssemblyDef.ReducedMemoryMode = True Call oDerivedAssemblyDef.SetHolePatchingOptions( _ DerivedHolePatchEnum.kDerivedPatchAll) ' Create the shrinkwrap component Dim oDerivedAssembly As DerivedAssemblyComponent _ = oPartDef.ReferenceComponents.DerivedAssemblyComponents _ .Add(oDerivedAssemblyDef) ' Save the part Dim PartFilename As String = WorkspacePath & "\OuterPart.ipt" ThisApplication.SilentOperation = True Call oPartDoc.SaveAs(PartFilename, False) ThisApplication.SilentOperation = False ' Create a substitute level of detail using the shrinkwrap part. Dim oSubstituteLOD As LevelOfDetailRepresentation = oAssyDef _ .RepresentationsManager.LevelOfDetailRepresentations _ .AddSubstitute(PartFilename) oSubstituteLOD.Name = "OuterBody" ThisApplication.SilentOperation = True Call oAssyDoc.Save() Call oAssyDoc.Close() ThisApplication.SilentOperation = False Return oPartDoc End Function 'ShrinkWrap Function SubtractPart(ByVal oSourcePartDoc As PartDocument, _ ByVal oOuterPartDoc As PartDocument) _ As PartDocument 'create new part Dim oDoc As PartDocument = CType(ThisApplication.Documents _ .Add(DocumentTypeEnum.kPartDocumentObject, , False), _ PartDocument) Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition ' Create the derived part 1 - Source body Dim oDerivedPartDef As DerivedPartUniformScaleDef _ = oDef.ReferenceComponents.DerivedPartComponents _ .CreateUniformScaleDef(oSourcePartDoc.FullFileName) Call oDef.ReferenceComponents.DerivedPartComponents _ .Add(CType(oDerivedPartDef, DerivedPartDefinition)) ' Create the derived part 2 - Outer body oDerivedPartDef = oDef.ReferenceComponents.DerivedPartComponents _ .CreateUniformScaleDef(oOuterPartDoc.FullFileName) Call oDef.ReferenceComponents.DerivedPartComponents _ .Add(CType(oDerivedPartDef, DerivedPartDefinition)) 'Subtract bodies Dim oColl As ObjectCollection = ThisApplication _ .TransientObjects.CreateObjectCollection Dim oCombineFeatures As CombineFeatures = oDef.Features.CombineFeatures Dim oBody1 As SurfaceBody = oDef.SurfaceBodies.Item(1) Dim oBody2 As SurfaceBody = oDef.SurfaceBodies.Item(2) Call oColl.Add(oBody1) Dim oCF As CombineFeature = oCombineFeatures _ .Add(oBody2, oColl, PartFeatureOperationEnum.kCutOperation, False) Return oDoc End Function 'SubtractPart
Thank you for your help with this. Unfortunately I have not been successful getting this to work. I copy and paste this in to an iLogic rule, select "Straight VB Code" from the options and once I run the code I get the following error. Is there something that I am doing incorrect?
Thank you,
Darek
I used Inventor 2013. The part file with my rule is attached.
Please try it.
Can you upload one of your models?
I figured out the issue. It turns out that Internet Explorer was adding or subtracting extra data. I installed Chrome and performed the coy and paste and it worked like a charm.
Thank you again for your help with this.
Darek
can you provide us a .txt file of the code?
i need to delete the derived part in Inventor using rules , can you provide me the code ?
wow and it thought i was a noob, see OP ^^^