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
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,