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: 

'Place from Vault' using ilogic or VBA

8 REPLIES 8
Reply
Message 1 of 9
waynehelley
2522 Views, 8 Replies

'Place from Vault' using ilogic or VBA

I currently have a code that will read a parts list from a spread sheet then place (with automatic imates) all the components into a blank assembly file.  As I have added imates to all the components it fully constrains it's self.

 

My problem is that if a user has no files locally, they will have to get all the files manually from vault before attempting to run the code.  I want some code that will GET all the files (including dependents).  Is this possible??

 

My current code is below

 

question = MessageBox.Show("Do you want to run the Configurator?", "Powell - Switchgear & Instrumentation Ltd.",MessageBoxButtons.YesNo,MessageBoxIcon.Question)

'set condition based on answer

If question = vbNo Exit Sub

End If

 

GoExcel.Open("C:\ARTICULATE\09\iLogic\Configurator", "Sheet1")

Dim oAsmCompDef As AssemblyComponentDefinition

oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

' Create a new matrix object. It will be initialized to an identity matrix.

Dim oMatrix As Matrix

oMatrix = ThisApplication.TransientGeometry.CreateMatrix

'Get the frame filename from spreadsheet

framefile=GoExcel.CellValue("A2")

' Place the frame.

Dim frame As ComponentOccurrence

frame = oAsmCompDef.Occurrences.Add(framefile, oMatrix)

'Get parts list from spreadsheet

Dim PartList As New ArrayList Dim row As Integer  

For row = 3 To 1000   

'Exits the FOR function when reaching the end of the list   

If (GoExcel.CellValue("A" & row) = "") Then 

Exit For   

End If  

PartList.add(GoExcel.CellValue("A"& row))        

Next  

 

'Place each part with automatic iMates

Dim oString as Object

i = 0

Dim oOccEnumerator As ComponentOccurrencesEnumerator 

For Each oString in PartList

oOccEnumerator = oAsmCompDef.Occurrences.AddUsingiMates(PartList.Item(i), False)

i=i+1

Next

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
8 REPLIES 8
Message 2 of 9

Has this problem been solved Wayne?

I have a similar problem and would like to get files from Vault aswell.

 

Hope to hear is soon!

Message 3 of 9

Hi there, unfortunately I didn't solve the problem!

 

I resorted to using error messages that prompt the user to download a file from vault if iLogic fails to place a component...

 

PlaceComponent:
Try
oOccEnumerator = oAsmCompDef.Occurrences.AddUsingiMates("C:\Work\Designs\Products\IEC Switchgear\Low Voltage\09090 IEC Type 439 EuroCentre\09090GT0000008\" & Frame & ".iam", False)
Catch
RetryBox=MessageBox.Show("Error loading Frame Assembly, C:\Work\Designs\Products\IEC Switchgear\Low Voltage\09090 IEC Type 439 EuroCentre\09090GT0000008\" & Frame & ".iam. Please GET the file from Vault.", "MCC Tier Configurator",MessageBoxButtons.RetryCancel,MessageBoxIcon.Exclamation)
If RetryBox=vbRetry
Goto PlaceComponent
Else
Return
End If
End Try

 

A couple of things I did learn though is that if you do a 'Replace' through iLogic, if Inventor finds that the file doesn't exist locally, Inventor asks the user if they want the file to be downloaded instead of Erroring out.

 

Taking this into account, in future I may avoid using 'Place' component functions in my iLogic code and instead just use 'Replace'.  If a component needs to not be present, you can 'Replace' for a dummy empty assembly. (I think you will have to get iLogic to set the BOM Structure to Phantom otherwise the dummy assembly will appear in the BOM).

 

Hope this helps!  Hopefully there will be some integration between Vault and iLogic in future versions.

 

 

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 4 of 9

Thanks! I will definitly try the Replace function, 'cause that is in fact what I need.
Hope it works!
Thanks again!
Message 5 of 9

Using the replace function works aslong as the files are 'Work in Progress'.

The moment they are not, an error occurs 'File not found: [Filename and Path]'

 

Hope this will change in the future!

Message 6 of 9
DRLTKSE
in reply to: waynehelley

"A couple of things I did learn though is that if you do a 'Replace' through iLogic, if Inventor finds that the file doesn't exist locally, Inventor asks the user if they want the file to be downloaded instead of Erroring out."

 

How did you do this? I tried to get this to work but it just errors out.

 

Here's my code:

 

SyntaxEditor Code Snippet

Dim ReplaceName As String
'Dim DocDoc As PartDocument = "K:\INVENTOR_DESIGNS\Vault Templates\TSKY Templates\TKSY WASHER TEMPLATE.ipt"
Dim oAsmCompDef As AssemblyComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition
Dim DocDoc As Document
Dim oOccurrence As ComponentOccurrence
Dim WashDoc As String 

ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, "K:\INVENTOR_DESIGNS\Vault Templates\TSKY Templates\TKSY WASHER TEMPLATE.ipt")
ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute2(True)
ThisApplication.ActiveDocument.Update2(-1)

i=0
'Iterate through all of the occurrences
For Each oOccurrence In oAsmCompDef.Occurrences
i=i+1
DocDoc = oOccurrence.Definition.Document
Next

WashDoc= ThisDoc.Document.ComponentDefinition.Occurrences.Item(i).Name

ReplaceName=(Left(DocDoc.DisplayName, (Len(DocDoc.DisplayName)-4))) & ":1"

MsgBox(ReplaceName)

Component.Replace(ReplaceName,"C:\Vault Workspace\Designs\Library Parts\TKSE STANDARDS\TKSY RINGS\P-0S-10-5-8-1.ipt", True)
Message 7 of 9
waynehelley
in reply to: DRLTKSE

My memory is a bit hazy on this but I am pretty sure I couldn't get it to work reliably.  I ended up adding some error handling to give the user a chance to retrieve the file from Vault before the code errors out.  I recently had a conversation with Symetri, my local Autodesk supplier, and apparenly you can add a direct link to the file in Vault within a message box.

 

PlaceComponent:

   

    If System.IO.File.Exists(C:\Vault Workspace\Designs\Library Parts\TKSE STANDARDS\TKSY RINGS\P-0S-10-5-8-1.ipt) Then

        

Component.Replace(ReplaceName,"C:\Vault Workspace\Designs\Library Parts\TKSE STANDARDS\TKSY RINGS\P-0S-10-5-8-1.ipt"        

 

    Else

   

    RetryBox=MessageBox.Show("C:\Vault Workspace\Designs\Library Parts\TKSE STANDARDS\TKSY RINGS\P-0S-10-5-8-1.ipt does not exist locally. Please download the file from Vault.", "Title",MessageBoxButtons.RetryCancel,MessageBoxIcon.Exclamation)

                If RetryBox=vbRetry

                Goto PlaceComponent

                Else

                'Return

                End If

 

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 8 of 9
waynehelley
in reply to: waynehelley

I just did a bit of research to work out how to create the hyperlink...

 

Your second point is possible today using the 'Copy hyperlink' command (formally called copy link).

1. Select a file in the Vault.

2. From the Edit menu, select 'Copy Hyperlink' command.

3. In email, choose Paste from your right-click context menu.

This will place a hyperlink in the email/word doc, etc...

 

(This is really cool. I need to add this to my code!)

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 9 of 9
DRLTKSE
in reply to: waynehelley

Thanks for your replies Wayne

 

I'm trying to use my code to generate a new part from a template file, but only if a part with the same attributes doesn't already exist. So the error proofing only works if you know the files do exist in vault. 

 

The hyperlink is really interesting, but I haven't been able to work out what I can do with this in iLogic yet.

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

Post to forums  

Autodesk Design & Make Report