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: 

Use ilogic to set the size and length of a part

25 REPLIES 25
SOLVED
Reply
Message 1 of 26
Anonymous
4328 Views, 25 Replies

Use ilogic to set the size and length of a part

Hi

 

I have created a ilogic rule that should set the size and the cut length of my parts. Most of the time the rule behave as I want it to. But sometime it gives me a error. See attached picture. It would be great if anyone could tell me what is wrong with the rule.. By the way, I have included this rule in my custom content center parts (beam's etc). The rule is:


'Turn off workfeatures
ThisDoc.Document.ObjectVisibility.AllWorkFeatures = False

'check if the part has any geometry
If Measure.ExtentsLength="0" Then

'sets values to 0 if no geometry exists
iProperties.Value("Custom", "G_L")="0"
iProperties.Value("Custom", "Size")="0,0,0"

'Turn on workfeatures
ThisDoc.Document.ObjectVisibility.AllWorkFeatures = True

Return

End If

'Sets size of part
iProperties.Value("Custom", "Size")=Round(Measure.ExtentsLength, 1) & "mmX" & Round(Measure.ExtentsWidth, 1) & "mmX" & Round(Measure.ExtentsHeight, 1) &"mm"

 

'Sets a value in the properties field G_L (cutlenght) based on what value that is written in the filed "kpl" (x,y or z)
If iProperties.Value("Custom", "kpl")="Z" Then
iProperties.Value("Custom", "G_L")=Round(Measure.ExtentsHeight, 0) & "mm"
Else If iProperties.Value("Custom", "kpl")="z" Then
iProperties.Value("Custom", "G_L")=Round(Measure.ExtentsHeight, 0) & "mm"
Else If iProperties.Value("Custom", "kpl")="X" Then
iProperties.Value("Custom", "G_L")=Round(Measure.ExtentsLength, 0) & "mm"
Else If iProperties.Value("Custom", "kpl")="x" Then
iProperties.Value("Custom", "G_L")=Round(Measure.ExtentsLength, 0) & "mm"
Else If iProperties.Value("Custom", "kpl")="Y" Then
iProperties.Value("Custom", "G_L")=Round(Measure.ExtentsWidth, 0) & "mm"
Else If iProperties.Value("Custom", "kpl")="y" Then
iProperties.Value("Custom", "G_L")=Round(Measure.ExtentsWidth, 0) & "mm"
Else iProperties.Value("Custom", "G_L")=iProperties.Value("Custom", "kpl")
End If

'Turn on workfeatures
ThisDoc.Document.ObjectVisibility.AllWorkFeatures = True

 

 

 

 

25 REPLIES 25
Message 21 of 26
MjDeck
in reply to: Anonymous

I still can't reproduce the problem, but please try the edited versions of two of your external rules in the attached zip file.  If they don't fix the problem, please send a new text capture of all the error information.  Also, please run the Tools -> Add-Ins command, and post a screenshot of the add-ins you have loaded.


Mike Deck
Software Developer
Autodesk, Inc.

Message 22 of 26
HermJan.Otterman
in reply to: MjDeck

I have a simmeler problem, with the same error, I wanted to get the boundingbox. the problem started after the work features were turned off (whith the same code as used here). before I added that part I didn't get the error but the workfetures interfered with the dimensions.

 

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 23 of 26
MjDeck
in reply to: MjDeck

If you're getting a "Member not found" error, the following should fix it.  Instead of


ThisDoc.Document.ObjectVisibility.AllWorkFeatures = False

try the following code:


Dim partDoc As PartDocument = TryCast(ThisDoc.Document, PartDocument)
Dim assemDoc As AssemblyDocument = TryCast(ThisDoc.Document, AssemblyDocument)

If (partDoc IsNot Nothing) Then
 partDoc.ObjectVisibility.AllWorkFeatures = False
Else
 assemDoc.ObjectVisibility.AllWorkFeatures = False
End If

 

If the rule is in a part (or always running in a part) then the assemDoc code is not required.
To turn visibility back on:

If (partDoc IsNot Nothing) Then
 partDoc.ObjectVisibility.AllWorkFeatures = True
Else
 assemDoc.ObjectVisibility.AllWorkFeatures = True
End If

 


Mike Deck
Software Developer
Autodesk, Inc.

Message 24 of 26
HermJan.Otterman
in reply to: MjDeck

Tanks Mike for you code,

it looks like it works fine now, we have had no error with this any more!

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 25 of 26
Anonymous
in reply to: MjDeck

Hi Mike,

 

I have been having this exact same problem with this code that was provided to me where every now and again for no apparent reason I get the Member not found error and only a save, close and re-open the assembly will cure the problem. Can you point to what is causing the problem here please? I have spent weeks trying to nail this down with no success.

 

Many thanks

Dim asmDoc As AssemblyDocument  
asmDoc = ThisApplication.ActiveDocument  
Dim asmDef As AssemblyComponentDefinition  
asmDef = asmDoc.ComponentDefinition 
Dim oComp As Inventor.ComponentOccurrence

For Each oDoc In ThisApplication.ActiveDocument.AllReferencedDocuments
    If oDoc.DocumentType = kPartDocumentObject Then
    Dim oFilename As String = IO.Path.GetFileName(oDoc.displayname)                            
    oDocName = oDoc.Displayname                         
    Dim oIVDesignInfo As PropertySet
    oIVDesignInfo = oDoc.PropertySets.Item("Design Tracking Properties")
    Dim oIVDocSumInfo As PropertySet
    oIVDocSumInfo = oDoc.PropertySets.Item("Inventor Document Summary Information")
    Dim oIVSumInfo As PropertySet
    oIVSumInfo = oDoc.PropertySets.Item("Inventor Summary Information")
    Dim oIVCustomSet As PropertySet
    oIVCustomSet = oDoc.PropertySets.Item("Inventor User Defined Properties")
        If oIVSumInfo.item("Keywords").Value = "ISM" Then
        oIVSumInfo.item("Title").Value = oDocName                                 
        oIVDesignInfo.item("Part Number").Value = JOB_NUMBER & "I" & part_no  	
		oIVDesignInfo.item("Stock Number").Value = " "
        Dim oCompDef As ComponentDefinition
        oCompDef = oDoc.ComponentDefinition
                                                
            If oCompDef.HasFlatPattern = False Then
            oCompDef.Unfold
            oDoc.Save
            oDoc.Close
            End If
            
        Dim sOut As String
        sOut = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=IV_OUTER_PROFILE&InvisibleLayers=IV_TANGENT;IV_BEND;IV_BEND_DOWN;IV_ROLL_TANGENT;IV_ARC_CENTERS"
        Dim sFname As String
        sFname = DXF_LOC & iProperties.Value(oDocName ,"Project", "Part Number") & ".dxf"                                   
        oCompDef.DataIO.WriteDataToFile(sOut, sFname)
		part_no = part_no + 1 
        Else
        End If
    End If
Next

 

 

 

 

 

 

Message 26 of 26
iLimbani
in reply to: MjDeck

This solution worked for me. Thank you so much

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report