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: Generate derived part

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
ddavis
5399 Views, 8 Replies

iLogic: Generate derived part

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.

 

Capture.JPG

 

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?

 

manifold.jpg

 

manifold_internals.jpg

 

Thanks for any help you may be able to furnish, I really appreciate it.

 

Darek Davis

Tags (2)
8 REPLIES 8
Message 2 of 9
Vladimir.Ananyev
in reply to: ddavis

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.

 

1.png2.PNG

 

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

 


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 3 of 9
ddavis
in reply to: Vladimir.Ananyev

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

 

Capture.JPG

Message 4 of 9
Vladimir.Ananyev
in reply to: ddavis

I used Inventor 2013.  The part file with my rule is attached. 
Please try it.

Can you upload one of your models?


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 5 of 9
ddavis
in reply to: Vladimir.Ananyev

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

Message 6 of 9

can you provide us a .txt file of the code?

Image and video hosting by TinyPic
..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................


See My LinkedIn Profile
Message 7 of 9
ddavis
in reply to: DeerSpotter

Attached you will find the code in a text file as requested.

 

Darek

Message 8 of 9
israel.parker
in reply to: ddavis

i need to delete the derived part in Inventor using rules  , can you provide me the code ?

Message 9 of 9
DeerSpotter
in reply to: israel.parker

wow and it thought i was a noob, see OP ^^^

Image and video hosting by TinyPic
..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................


See My LinkedIn Profile

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

Post to forums  

Autodesk Design & Make Report