Shrinkwrap using iLogic

Shrinkwrap using iLogic

Anonymous
Not applicable
4,179 Views
5 Replies
Message 1 of 6

Shrinkwrap using iLogic

Anonymous
Not applicable

Hi guys, I'm trying to automate making a shrinkwrap of some assemblies that I made that are also configurable using iLogic. I want to be able to make a shrinkwrap of the Assembly without having a substitute representation and also break the link with the Assembly so we can make a 3D block Library.

 

I tried using the sample code in the Programming Help but I keep getting an error. I made a simple counting function to see where I'm going wrong and I've narrowed it down to after count #6.

 

I'm using a 64bit Windows 7 computer with the Factory Design Suite on it. Factor Design Suite is mostly just an add-on to Inventor 2011 so I'm not sure if that is causing the error.

 

I have some experience with programming but I haven't had any formal VBA classes so I've been mostly just guessing and running it to try to fix the problem but I've run into a wall. Can someone tell me what I'm doing wrong? 

 

Here is my code and the error that it gives me when I try to run it:

 

Code:

 

Sub CreateShrinkwrap(ShrinkwrapFolder As String)

Parameter("COUNT") = 0

' Find the part File Path and Name
PART_NUMBER = iProperties.Value("Project", "Part Number")

ShrinkwrapFilePath = String.Concat("L:\Mechanical\Inventor\COMPONENT DETAILS\", ShrinkwrapFolder, "\")

ShrinkwrapFileName = String.Concat(ShrinkwrapFilePath, PART_NUMBER, ".ipt")

Call SET_COUNT() 'COUNT = 1

' Set a reference to the active assembly document
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

Call SET_COUNT() 'COUNT = 2

Dim oDef As AssemblyComponentDefinition
oDef = oDoc.ComponentDefinition

Call SET_COUNT() 'COUNT = 3

'Set the Template file name:
TemplateFileName = "\\fs3\Depts\Product_Engineering\Inventor_File_Repository\INVENTOR 2011 FILES\Templates\Shrinkwrap.ipt"

' Create a new part document that will be the shrinkwrap substitute
Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, TemplateFileName, False)

Call SET_COUNT() 'COUNT = 4

Dim oPartDef As PartComponentDefinition
oPartDef = oPartDoc.ComponentDefinition

Call SET_COUNT() 'COUNT = 5

Dim oDerivedAssemblyDef As DerivedAssemblyDefinition
oDerivedAssemblyDef = oPartDef.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition(oDoc.FullDocumentName)

Call SET_COUNT() 'COUNT = 6

' Set various shrinkwrap related options
oDerivedAssemblyDef.DeriveStyle = kDeriveAsSingleBodyNoSeams
oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = kDerivedIncludeAll
oDerivedAssemblyDef.IncludeAllTopLevelSketches = kDerivedIncludeAll
oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = kDerivedExcludeAll
oDerivedAssemblyDef.IncludeAllTopLevelParameters = kDerivedExcludeAll
oDerivedAssemblyDef.ReducedMemoryMode = True

Call oDerivedAssemblyDef.SetHolePatchingOptions(kDerivedPatchAll)
Call oDerivedAssemblyDef.SetRemoveByVisibilityOptions(kDerivedRemovePartsAndFaces, 25)

Call SET_COUNT() 'COUNT = 7

' Create the shrinkwrap component
Dim oDerivedAssembly As DerivedAssemblyComponent
oDerivedAssembly = oPartDef.ReferenceComponents.DerivedAssemblyComponents.Add(oDerivedAssemblyDef)
oDerivedAssembly.BreakLinkToFile

Call SET_COUNT() 'COUNT = 8

ThisApplication.SilentOperation = True
oPartDoc.SaveAs(ShrinkwrapFileName, False)
ThisApplication.SilentOperation = False

Call SET_COUNT() 'COUNT = 9

' Release reference of the invisibly opened part document.
oPartDoc.ReleaseReference

Call SET_COUNT() 'COUNT = 10

End Sub

 

Error Message:

 

Error in rule: MAKE SHRINKWRAP, in document: 1354-8000.iam

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

 

More Info:

 

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Inventor.DerivedAssemblyDefinition.set_IncludeAllTopLevelWorkFeatures(DerivedComponentOptionEnum )
   at LmiRuleScript.CreateShrinkwrap(String ShrinkwrapFolder)
   at LmiRuleScript.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at p.b(String A_0)

0 Likes
Accepted solutions (1)
4,180 Views
5 Replies
Replies (5)
Message 2 of 6

MjDeck
Autodesk
Autodesk

You can fix this problem by adding these lines at the top of your rule:

 

Imports Inventor.DerivedComponentStyleEnum
Imports Inventor.DerivedComponentOptionEnum
Imports Inventor.DerivedHolePatchEnum
Imports Inventor.DerivedGeometryRemovalEnum

These are required because in VB.NET (and thus in iLogic), Enum's are not automatically imported by the compiler.  

 

Alternatively, you can change your code to explicitly use the Enum names wherever needed, e.g.

oDerivedAssemblyDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsSingleBodyNoSeams

 

To find the required Enum names:

Any time you use a predefined Inventor constant (which usually starts with the letter k), search the API help for it.  This will give you the Enum type where the constant is found.

 

 To make sure you have found all the constants in your code, you can add the line:

Option Explicit On

at the top of the rule (before the Imports statements).

 


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 3 of 6

Anonymous
Not applicable

Thanks MjDeck but I'm still having problems. I put those Imports statements at the top of the rule and I'm getting an error:

 

Error Message:

Error in rule: MAKE SHRINKWRAP, in document: 1354-8000.iam

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

 

More Info:

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Inventor.DerivedAssemblyDefinition.set_IncludeAllTopLevelWorkFeatures(DerivedComponentOptionEnum )
   at LmiRuleScript.CreateShrinkwrap(String ShrinkwrapFolder)
   at LmiRuleScript.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at p.b(String A_0)

 

So I still don't know what I'm doing wrong. I attached a copy of my full code if that helps any. Thanks again for the help.

0 Likes
Message 4 of 6

MjDeck
Autodesk
Autodesk

Did you try the your code in VBA?   It might be easier to see what's going wrong in VBA.

 

If it works in VBA, can you post your template file Shrinkwrap.ipt and a sample assembly?

 

 


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 5 of 6

Anonymous
Not applicable
Accepted solution

Using the "Imports" command didn't really work very well but with a little work I did get it to work using the VB editor. Thanks for all the help.

0 Likes
Message 6 of 6

warrentdo
Collaborator
Collaborator

Hello Gatordanner,

 

Did you manage to get the I-logic to work.

I am trying to get it to work.

 

Regards,

 

Warren.

0 Likes