- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I'm trying to create a macro functionning for all parts if the active document is an assembly, or on the part if it is a part. Something like this :
Dim oRefDocs As DocumentsEnumerator
Dim oRefDoc As Document
Dim odoc As Document
Set odoc = ThisApplication.ActiveDocument
If odoc.DocumentType = kAssemblyDocumentObject Then Set oRefDocs = odoc.AllReferencedDocuments
If odoc.DocumentType = kPartDocumentObject Then Set oRefDocs = odoc
For each oRefDoc in oRefDocs
...
next
The red line does not function, and I'm stuck... any idea ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
What are you attempting to use that document variable for later in your macro? You may need to define it as its true document type (PartDocument or AssemblyDocument) before it will allow certain actions/access related to it.
Here is one approach (of many):
Dim oDocType As DocumentTypeEnum
Set oDocType = ThisApplication.ActiveDocumentType
If oDocType = kPartDocumentObject Then
Dim oPDoc As PartDocument
Set oPDoc = ThisApplication.ActiveDocument
GoTo PartStart '(place in code dealing with PartDocument stuff)
ElseIf oDocType = kAssemblyDocumentObject Then
Dim oADoc As AssemblyDocument
Set oADoc = ThisApplication.ActiveDocument
GoTo AsmStart '(place in code dealing with AssemblyDocument stuff)
End If
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE'
.
If you have time, please... Vote For My IDEAS
or you can Explore My CONTRIBUTIONS
Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I agree with your approach. To be more specific, I currently have an iLogic rule that works for iam. This rule is a treatment for all components of the iam. I'm trying to adapt it so that it works the same way for one part. The current code is of the type :
oRefDocs = ThisDoc.Document.AllReferencedDocuments
For Each oRefDoc In oRefDocs
...
Next oRefDoc
What I'm trying to do is to make oRefDocs contain AllreferencedDocuments if the file is an iam, or contain the file itself if it is a part.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The DocumentsEnumerator Object can't be set to a single document from an open part file. You could use the Application.Documents.VisibleDocuments, but you would then have to remove those you don't want if more than 1 document is open.
Alternatively, if you use an ObjectCollection Object , then you could fill it with AllReferencedDocuments from assembly files or with the "odoc" by itself if it is a part.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
"The DocumentsEnumerator Object can't be set to a single document from an open part file."
Yes, that's the problem...
"Alternatively, if you use an ObjectCollection Object "
That's the workaround I use. I thought there was a better solution. The DocumentsEnumeratorObject contains Documents, ActiveDocument is a document, so I don't understand why I can't fill a DocumentsEnumeratorObject with a Document...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The DocumentsEnumerator Object can't be filled because it has no method for Add/Remove. The only properties it has are: Count, Item, & Type. You have to set it to another DocumentsEnumerator Object, like AllReferencedDocuments, in order for it to be "filled".