How to use the name of unsaved document with VBA ?

How to use the name of unsaved document with VBA ?

Olsndot
Enthusiast Enthusiast
540 Views
5 Replies
Message 1 of 6

How to use the name of unsaved document with VBA ?

Olsndot
Enthusiast
Enthusiast

Hi

With VBA, I try to create document with serial number of the file name.

But when the name is same as unsaved document created with Inventor command "Create In-Place Component" my code is not avoid to give same name.

How to use the name property of unsaved document with VBA ?

 

0 Likes
541 Views
5 Replies
Replies (5)
Message 2 of 6

AlexFielder
Advisor
Advisor

Can you make a screencast showing the issue you're having?

 

In my experience, any time you want to get the name of a document (via the API), it needs to have been saved first.

 

Someone may have an example that shows otherwise, or perhaps be able to demonstrate a different method of naming the file in the first place; a short video showing the issue you're having would help with both.

 

If you can also share the VBA you have so far that would help too.

0 Likes
Message 3 of 6

bradeneuropeArthur
Mentor
Mentor

You should use "On populate Metadata" event, when creating the filename.

This will avoid that..

 

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 4 of 6

Olsndot
Enthusiast
Enthusiast

Thank you for reply!

I was examined various about that, but I can't do that because my understanding of VBA is lacking...

0 Likes
Message 5 of 6

Olsndot
Enthusiast
Enthusiast

Thank you for reply!

I try to create a part within assembly with displaying the thumbnail of template.

So, what I try to do is the following in sequence.

 

1.Save the template file in the folder "Content Center Files" in advance.
2.Place the template file from the folder "Content Center Files" with command "Place Component".
3.Copy the file to the folder in Workspace with serial number.
4.Replace the template file with the copy.

 

The problem has occurred at step 3.
When name of new file is same as the unsaved part created with name by command "Create In-Place Component" or "Copy Component",
the unsaved part isn't exist in the folder, so New file is overwritten by the unsaved part as shown in screencast.
So, I should check the new file name with the unsaved parts name, but I don't know how to do.
How should I do?

The code is as below,and screencast is posted.

Sub PlaceTemplate()

Call ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute
Do
    ThisApplication.UserInterfaceManager.DoEvents
    
Loop Until ThisApplication.CommandManager.ActiveCommand <> "AssemblyPlaceComponentCmd"

Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveEditDocument

Dim oTopDoc As AssemblyDocument
Set oTopDoc = ThisApplication.ActiveDocument

Dim oEditOccu As ComponentOccurrence
Set oEditOccu = oTopDoc.ComponentDefinition.ActiveOccurrence

Dim oOcc As ComponentOccurrence
Dim oOccName As String

Dim oNewDocNum As String
oNewDocNum = oAsmDoc.ComponentDefinition.Occurrences.Count

'Within sub assembly or top assembly
If Not (oAsmDoc Is oTopDoc) Then

    Set oOcc = oEditOccu.SubOccurrences.Item(oNewDocNum)

    Else
    
    Set oOcc = oAsmDoc.ComponentDefinition.Occurrences.Item(oNewDocNum)
  
End If
oOccName = oOcc.Definition.Document.FullFileName
'Specify the folder
Dim oWSPath As String
oWSPath = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath + "\PART\"

  
'Specify the file name
Dim oNewOccName As String
oNewOccName = oWSPath + "TEST" + Format(Date, "yymmdd") + "_PART"
  
'Confirm the existence of the file

If Dir(oWSPath, vbDirectory) = "" Then
    MkDir (oWSPath)
End If

Dim fCount As Integer
Dim oNewPart As String
For fCount = 1 To 999
    oNewPart = oNewOccName + CStr(fCount) + ".ipt"
    If Dir(oNewPart) = "" Then

        Call ThisApplication.FileManager.CopyFile(oOccName, oNewPart)

        'Replace component
        Call oOcc.Replace(oNewPart, True)
        Exit For
    End If

Next

End Sub

Thank you.

0 Likes
Message 6 of 6

Olsndot
Enthusiast
Enthusiast

 

 

 

0 Likes