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: 

Apply different changes to select parts in an assembly

2 REPLIES 2
Reply
Message 1 of 3
earlgreyspartan
306 Views, 2 Replies

Apply different changes to select parts in an assembly

I'm VERY new to ilogic so I'm on a steep learning curve right now. I'm hoping the answer to this is something easy!

 

I have an Excel file that generates parameters that drives the geometry of parts called "Hook-(thickness)-V0.ipt" and "Straight-(thickness)-V0.ipt"

 

I currently have a rule (which I didn't originally write, just edited) in each of the part files that changes the PART NUMBER based on the parameter the spreadsheet gives it for thickness (HLt or SLt). The FILE NAME of the original does not change, but a new part is created with the FILE NAME and PART NUMBER being the new values.

 

InventorVb.DocumentUpdate()
newname = ThisDoc.FileName(False)
posx = InStr (newname, "(")
If posx >0 Then newname = Left(newname,posx-1)
Parameter.Quiet = True
iProperties.Value("Project", "Part Number") = newname & Parameter("SLt") & "-V0"
'MsgBox("Current Part Number = " & iProperties.Value("Project", "Part Number"))FileToSave = ThisDoc.Path & "\" & iProperties.Value("Project", "Part Number") & ".ipt"
If IO.File.Exists(FileToSave) Then
'MsgBox("Member already exists")Else
MsgBox("New part file being created : " & FileToSave)
ThisDoc.Document.SaveAs(FileToSave , True)
End If

 

For example:

 

The part is "Hook-(thickness)-V0.ipt." The Excel file passes a thickness parameter of 0.105 to this part. When I rule my part-level rule, a NEW file is created with the FILE NAME reading "Hook-0.105-V0.ipt" and the PART NUMBER reading "Hook-0.105-V0" if it didn't already exist. However, the part "Hook-(thickness)-V0.ipt." FILE NAME remains unchanged but the PART NUMBER is changed to "Hook-0.105-V0" 

 

Multiple occurrences of each "Hook-(thickness)-V0.ipt." and "Straight-(thickness)-V0.ipt" are in an assembly. However, I need the BOM quantity for each of these parts to be overriden by values provided by the Excel spreadsheet (bomHL and bomSL). This is the current rule I have:

 

ThisBOM.OverrideQuantity("Model Data","Hook-" &HLt & "-V0",bomHL)
ThisBOM.OverrideQuantity("Model Data","Straight-"&SLt&"-V0",bomSL)

 

 

I make changes to the spreadsheet, which changes parameters in the assembly and the parts. However, because I haven't ran the rules in each part to assign it a new part number (based on the values for HLt or SLt)  the BOM qty override can't find the part.

 

How can I accomplish the PART NUMBER changes for every occurrence of each of these parts in the assembly without having to seperately open each part first, and run the part-level rule?

 

Thanks!

 

 

 

2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: earlgreyspartan

I don't know the full answer, but have you read this?

 

http://download.autodesk.com/us/community/mfg/Part_3.pdf

 

The document based stuff starts on page 5...It's part 3 of the series.

 

 

Also, have you tried editing the source code to the CopyDesign program in the Inventor SDK? The source code can be found at:

C:\Program Files\Autodesk\Inventor 2011\SDK

Or your equivalent of that. Install UserTools.msi and look for "CopyDesign" this should do half of what you want and the ReadMe welcomes users to take it and edit it to their needs.

 

 

Like I said, I don't know the answer! I'm new too! But hopefully this helps!

Message 3 of 3
Anonymous
in reply to: earlgreyspartan

And something a little closer....are you trying to rename the files? That's what it seems like to me...

 

I'm still working on the replace component part....but here is what I have for the renaming part. HOWEVER, this does not link to excel. I'm not sure how to do that. This goes straight to explorer to be renamed.

 

Form 1: Browse

 

Public Sub Browse_Click()

Dim pathSelected As String
Dim ShellApp As Object
Set ShellApp = CreateObject("Shell.Application"). _
BrowseforFolder(0, "Choose Folder", 0, OpenAt)
pathSelected = ShellApp.self.Path
Me.TextBox1.Text = pathSelected
Set ShellApp = Nothing

End Sub

Private Sub Cancel_Click()         'Triggers the cancel command
    Unload Me
End Sub

Public Sub Rename_Click()

Renamer.Show vbModal               'Shows Renamer form and changes active form
Browser.Hide                       'Hides Browser form

End Sub

 

Form 2: Renamer

Private Sub Apply_Click()
'This will initiate Module 1 to do a batch rename to find and replace all
'Module 1 will then initiate the resolving links process

Dim i As Integer
Dim from_str As String
Dim to_str As String
Dim dir_path As String


    from_str = Old_Name_Display.Text
    to_str = New_Name.Text

    dir_path = Path_Text.Text
    If Right$(dir_path, 1) <> "\" Then dir_path = dir_path _
        & "\"

    Old_Name_Display = dir$(dir_path & "*.*", vbNormal)
    Do While Len(Old_Name_Display) > 0
        ' Rename this file.
        New_Name = Replace$(Old_Name_Display, from_str, to_str)
        If New_Name <> Old_Name_Display Then
Name dir_path & Old_Name_Display.Text As dir_path & New_Name.Text
            i = i + 1
        End If

        ' Get the next file.
        Old_Name_Display = dir$()
    Loop

    Dim intResponse As Integer
    intResponse = MsgBox("Success!", vbInformation, "Renaming Result") 'Alerts user to success
    If intResponse = vbOK Then
    MsgBox "Please manually rename your folder before proceeding. Windows Explorer will now open in your task bar" _
    , vbExclamation, "Procedures Paused" _
    'Prepares resolve link process
    Else: End
    End If
    
    If intResponse = vbOK Then
    shell ("C:\WINDOWS\explorer.exe")
    Else: End
    End If
    
    
    Renamer.Hide
    Resolve.Show vbModal
    
    Exit Sub

'Parts of renaming process used from VB Helper, sponsored by Rocky Mountain Computer Consulting, Inc. _
Copyright 1997-2010; original code available at http://www.vb-helper.com/howto_rename_files.html _
edited to suit the needs of this project.


End Sub

Private Sub Cancel_Click()        'Triggers cancel button
    
    Unload Me

End Sub

Private Sub UserForm_Activate()

Path_Text.Text = Browser.TextBox1.Text 'Displays old name in old name text box

End Sub

 

 

And from there is the resolve part which I'm still working on it. Right now, Form3 automatically goes to the previously selected path to display .iam files only. I have a JPEG of my...I guess it's a process map?
Of what I am doing next...I'm stuck at Open_Assembly right now.

Process Map 2.JPG

Hopefully this is what you are looking for. I'm not entirely sure. If my codes didn't make sense, I can also send you the JPEGs of the forms. That should make it clearer.

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

Post to forums  

Autodesk Design & Make Report