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: 

Copy Revision Number from Drawing to attached part

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Gwennberg
194 Views, 2 Replies

Copy Revision Number from Drawing to attached part

Hi

I try to copy "Revision Number" from drawing to reference part and got Microsoft Copilot to help me but not to the goal line :-). The code is like this:

' Kontrollera att det aktiva dokumentet är en ritning
If ThisApplication.ActiveDocument.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
    MessageBox.Show("Detta skript fungerar endast med ritningsdokument.", "Fel")
    Return
End If

' Hämta ritningsrevisionen
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.ActiveDocument

Dim revision As String
revision = iProperties.Value("Project","Revision Number")

' Kontrollera att det finns en kopplad partfil
If oDrawingDoc.ReferencedDocumentDescriptors.Count = 0 Then
    MessageBox.Show("Ingen kopplad partfil hittades.", "Fel")
    Return
End If


' Hämta den första kopplade partfilen
Dim oPartDescriptor As DocumentDescriptor
oPartDescriptor = oDrawingDoc.ReferencedDocumentDescriptors.Item(1)


' Kontrollera om partfilen redan är öppen
Dim oPartDoc As PartDocument
If oPartDescriptor.ReferencedDocument Is Nothing Then
    ' Öppna partfilen om den inte redan är öppen
    oPartDoc = ThisApplication.Documents.Open(oPartDescriptor.FullDocumentName, False)
Else
    ' Använd den redan öppna dokumentreferensen
    oPartDoc = oPartDescriptor.ReferencedDocument
End If

' Sätt iProperty "Revision Number" i den kopplade partfilen
iProperties.Value(oPartDoc,"Project","Revision Number") = revision
MessageBox.Show("Revisionsbokstaven har uppdaterats till: " & revision, "Uppdatering Klar")

 

2 REPLIES 2
Message 2 of 3
WCrihfield
in reply to: Gwennberg

Hi @Gwennberg.  Try changing the following line in your code:

iProperties.Value(oPartDoc,"Project","Revision Number") = revision

...to be like this:

iProperties.Value(oPartDoc.DisplayName,"Project","Revision Number") = revision

...because that first (of 3) inputs is wanting a String.  Sometimes the Document.DisplayName property value will work there, and if not, you can try extracting the file name (no file path) of that document, and using that in that position.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3
Gwennberg
in reply to: Gwennberg

Thank's WCrihfield. It worked!
//Goran

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

Post to forums  

Autodesk Design & Make Report