Save and replace Ilogic

Save and replace Ilogic

Anonymous
Not applicable
2,696 Views
8 Replies
Message 1 of 9

Save and replace Ilogic

Anonymous
Not applicable

I found this code on the forum that is good to call the command :

 

The command name to use is : "AssemblyBonusTools_SaveAndReplaceComponentCmd"

 

put this in a iLogic rule:

 

    ' Get the CommandManager object.
    Dim oCommandMgr As CommandManager
   oCommandMgr = ThisApplication.CommandManager

    ' Get control definition for the line command.
    Dim oControlDef As ControlDefinition
    oControlDef = oCommandMgr.ControlDefinitions.Item( _
                                                 "AssemblyBonusTools_SaveAndReplaceComponentCmd") 
    ' Execute the command.
    oControlDef.Execute

 

But what i'm trying to do (with out success yet) is to create an Ilogic that will call the save and replace cmd for all components (parts, assembly and sub assembly) that the Iprop, part number is empty.

 

If someone can help me for that i will apreciate!

 

 

 

0 Likes
Accepted solutions (1)
2,697 Views
8 Replies
Replies (8)
Message 2 of 9

MechMachineMan
Advisor
Advisor
Accepted solution
 Dim oDoc AS Document
oDoc = ThisDoc.Document

Dim oSS AS SelectSet
oSS = oDOc.SelectSet

Dim oCommandMgr As CommandManager
oCommandMgr = ThisApplication.CommandManager

Dim oControlDef As ControlDefinition
oControlDef = oCommandMgr.ControlDefinitions.Item("AssemblyBonusTools_SaveAndReplaceComponentCmd")

For Each oOcc in oDoc.ComponentDefinition.Occurrences.AllLeafOccurrences
If oOcc.Definition.Document.PropertySets("Design Tracking Properties")("Part Number").Value = "" oSS.Clear
oSS.Select(oOcc) oControlDef.Execute
End if
Next

--------------------------------------
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
Message 3 of 9

Anonymous
Not applicable

Exactly what was looking for.

Many tks. Mechmachine

0 Likes
Message 4 of 9

Anonymous
Not applicable

Just realize that working for all parts and sub assembly parts, but do not work with sub assembly

0 Likes
Message 5 of 9

marcin_otręba
Advisor
Advisor

You want to put new names(numbers) for such files manually or by code ?

 

This method affects only selected file, so if you have more than 1 occurrence in assembly, or file occurs in subassemblies then you will get massive fails...

 

In my codes i use saveas instead because i noticed that if it is saved from code then save as method replace that file in all opened documents...:

 

 

doc.SaveAs newname,  False

 

then if file is member of assembly, and that assembly is opened then it is replaced without any further functions or procedures... it works for *.ipt, and*.iam files.

 

if you dont want to replace use:

 

doc.SaveAs newname,  True

 

true/false means that you saveascopy or not.

 

in my opinion this is the best way to do it because you don't need to bother with checking for all occurs of replaced file, you need only to remember that it will be replaced in all opened assemblies.

 

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 6 of 9

Anonymous
Not applicable

can we add an open the file, after the save replace command is done

0 Likes
Message 7 of 9

o.sassen
Participant
Participant

Hi All, 

 

one additional question to the subject. we have an assembly with iparts. But we want to save the files as custom part. but we need the vault to fill in the names. (numbering). So we are using the command "AssemblyBonusTools_SaveAndReplaceComponentCmd". But for every part we gat an window to accept and save te name. is it possible to automatically save the suggested name? 

I thanks you in advance. 

Yours, 

 

0 Likes
Message 8 of 9

nbarbars
Enthusiast
Enthusiast

How can i have this work for a specific part name without selecting the part? not sure how to call on the part that needs to be saved as. I just need to have it save and replace "beam_width" component if the length parameter is x long

0 Likes
Message 9 of 9

rprivittB3TTG
Enthusiast
Enthusiast

I am needing a similar solution. Example:

 

FrameAssembly.iam

     - FrameSketch.ipt

 

I need to replace the FrameSketch.ipt with a new part with a constructed part number. The constructed part number code is already established. I just need the simplest code for replacing the sketch part. The name of the sketch part never changes because it is a template added to the FrameAssembly.iam template.

0 Likes