Save As all occurrences from an assembly

Save As all occurrences from an assembly

JorisSteurs1246
Advocate Advocate
1,038 Views
4 Replies
Message 1 of 5

Save As all occurrences from an assembly

JorisSteurs1246
Advocate
Advocate

The code below should make a copy of every part in an assembly and save it with a specific File name.

 

I think I have it all right up to the moment the part needs to be saved , I get an unknow error.

Any ideas what is going on here?

 

SyntaxEditor Code Snippet

  'check this file is an assembly
        Dim doc As Document = ThisApplication.ActiveDocument
        If doc.DocumentType = kPartDocumentObject Then
            MessageBox.Show("This rule can only be run in an assembly file!", "Cadline iLogic")
            Return
        End If

Dim newname As String
Dim compdef As ComponentDefinition
compdef = doc.ComponentDefinition
If (doc.documenttype = 12291) Then ' only do this for assembly or subassembly
 For Each occ In compdef.Occurrences
    If (occ.definition.type =83886592) Then ' only do this for part
         Dim oNewDoc As PartDocument
          oNewDoc = ThisApplication.Documents.Add(kPartDocumentObject, , False)
            occ.Name =  iProperties.Value(occ.Name,"Project", "Part Number")
             newname = iProperties.Value(occ.Name,"Project", "Part Number") & ".ipt"
            MessageBox.Show("I found variable: " & newname , "Info")
             ThisApplication.SilentOperation = True
               'oNewDoc = occ.Definiton.Document.SaveAs(newname, True)    
            oNewDoc.SaveAs(newname, False)    
            ThisApplication.SilentOperation = False
            
    End If
 Next 
End If
0 Likes
1,039 Views
4 Replies
Replies (4)
Message 2 of 5

Jef_E
Collaborator
Collaborator

You are making a new empty document? And then saving it as another empty document?

 

Dim oNewDoc As PartDocument
oNewDoc = ThisApplication.Documents.Add(kPartDocumentObject, , False)

 

 



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 3 of 5

JorisSteurs1246
Advocate
Advocate

you are right , right now a new empty document is created, 

but I don't manage to save it with a new name.

It goes wrong at this line

 

oNewDoc.SaveAs(newname, False)

my final goal is to save out an occurrence from the  assembly with another filename. 

0 Likes
Message 4 of 5

MechMachineMan
Advisor
Advisor

If you are trying to make a smart way to rename parts, I hope you realize that without replacing references within your code, your file references will be all messed up.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 5 of 5

JorisSteurs1246
Advocate
Advocate

The command I use now manually now  you find under the productivity tab, called "save and Replace Component". 

The goal is get some code together that loops trough the assembly and saves every part by its partnumber.

If I do this manually with the "save and Replace Component" all the references and constrains are still OK , so I assume it will not be different when using iLogic?

0 Likes