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 Custom iProperties & Virtual Components

1 REPLY 1
Reply
Message 1 of 2
edd_3
1067 Views, 1 Reply

iLogic Custom iProperties & Virtual Components

Hello

I have been trying to get standard Virtual parts working with all of the Custom iProperties we require for our Sage uploader.

I just have the last bit to get it all working nicely.

I need a "Short Description" preferably from the virtual parts description using Left("",20).

Can anyone help?

Thanks

Here is the code so far:-

SubMain()

 

DimMyArrayListAsNewArrayList

MyArrayList = GoExcel.CellValues("\\MW-FS01\Inventor\Virtual Components.xlsx", "Adhesive", "A2", "A1000")

DimsVirtPartAsString

'get user input from list

sVirtPart = InputListBox("Select a virtual part to add.", _

MyArrayList, MyArrayList.Item(0), "iLogic", "Standard Virtual Parts")

'check for empty input in the case where the user cancels out of the input box

IfsVirtPart = ""Then

Return'end rule

Else

EndIf

 

 

'get iProperties from the XLS file

ForMyRow = 2 To 1000 'index row 2 through 1000

               'find the cell in column A that matches the user selection

                 IfsVirtPart = (GoExcel.CellValue("A"&MyRow))Then

           'get the iProperty from the XLS file for each coluGoExcel.CellValue("filename.xls", "Sheet1", "A2")mn

               oProp1 = GoExcel.CellValue("A"&MyRow )

           oProp2 = GoExcel.CellValue("C"&MyRow )

           oProp4 = GoExcel.CellValue("D"&MyRow)

           oProp5 = GoExcel.CellValue("E"&MyRow)

          ExitFor

           EndIf

Next

 

 

'get quantity from user

iQTY = InputBox("Enter the TOTAL number of:"_

& vbLf &"       ''"&sVirtPart&"''"_

& vbLf &"to place in the assembly."_

& vbLf & vbLf &"Note: Enter 0 to delete all existing instances.", "iLogic", "1")

'check for empty input in the case where the user cancels out of the input box

IfiQTY = ""Then

Return'end rule

Else

EndIf

 

 

'define assembly

DimasmDocAsAssemblyDocument

asmDoc = ThisApplication.ActiveDocument

'define assembly Component Definition

DimoAsmCompDefAsAssemblyComponentDefinition

oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

 

 

'Iterate through all of the occurrences in the assembly

DimasmOccAsComponentOccurrence

ForEachasmOccInoAsmCompDef.Occurrences

               'get name of occurence only (sees only everything left of the colon)

               DimoOccAsObject

           oOcc = asmOcc.Name.Split(":")(0)

           'look at only virtual components

               IfTypeOfasmOcc.DefinitionIsVirtualComponentDefinitionThen

                       'compare name selected from list to the

                               'existing virtual parts

                                IfoOcc = sVirtPartThen

                       'delete existing virtual parts if name matches

                               asmOcc.delete

                               Else

                       EndIf

           Else

           EndIf

Next

DimoccsAsComponentOccurrences

occs = asmDoc.ComponentDefinition.Occurrences

DimidentityAsMatrix

identity = ThisApplication.TransientGeometry.CreateMatrix

 

 

'create first instance of the virtual part

DimvirtOccAsComponentOccurrence

IfiQTY >= 1 Then

virtOcc = occs.AddVirtual(sVirtPart, identity)

           Try

           iProperties.Value(sVirtPart&":1", "Project", "Description") = oProp1

               Catch'catch error when oProp1 = nothing

               EndTry

           Try

         iProperties.Value(sVirtPart&":1", "Project", "Part Number") = oProp2

               Catch'catch error when oProp2 = nothing

               EndTry

           Try

           iProperties.Value(sVirtPart&":1", "Project", "Revision Number") = oProp3

               Catch'catch error when oProp3 = nothing

               EndTry

           Try

           iProperties.Value(sVirtPart&":1", "Project", "Vendor") = oProp4

               Catch'catch error when oProp4 = nothing

               EndTry

           Try

           iProperties.Value(sVirtPart&":1", "Summary", "Comments") = oProp5

               Catch'catch error when oProp5 = nothing

               EndTry

Else

Return

EndIf

 

 

'add next instance starting at instance2 (if applicable)

DimindexAsInteger

index = 2

DoWhileindex <= iQTY

occs.AddByComponentDefinition(virtOcc.Definition, identity)

index+= 1

Loop

 

CreateCustomIprop(virtOcc,"Made or Bought","B")

 

CreateCustomIprop(virtOcc,"Material Type","RM")

 

CreateCustomIprop(virtOcc,"Product Type","M101")

 

CreateCustomIprop(virtOcc,"Base Unit","KG")

 

CreateCustomIprop(virtOcc,"Short Description",(iProperties.Value("Project", "Description")))

 

End Sub

 

PrivateSubCreateCustomIprop(propertyOcc, propertyName, propertyValue)

 

customPropertySet = propertyOcc.definition.PropertySets.Item("Inventor User Defined Properties")

Try

prop = customPropertySet.Item(propertyName)

Catch

' Assume error means not found

prop = customPropertySet.Add("", propertyName)

EndTry

 

prop.Value = propertyValue

 

End Sub

 

1 REPLY 1
Message 2 of 2
adam.nagy
in reply to: edd_3

Hi,

 

I'm not sure what your real question is because you already know what function you can use to get the first 20 characters of a string, and you are already getting properties from the virtual component.

Btw, you could also do it like this: iProperties.Value(virtOcc.Name, "Project", "Part Number")

 

Dim shortDesc = Left(iProperties.Value(virtOcc.Name, "Project", "Description"), 20)

 

Cheers,

 



Adam Nagy
Autodesk Platform Services

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

Post to forums  

Autodesk Design & Make Report