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: 

Edit filename of iAssembly Table Member in ilogic

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
danmorick
1264 Views, 5 Replies

Edit filename of iAssembly Table Member in ilogic

Hi,

 

Can anyone show me how to edit the member name in an iassembly table using code?  The Part Number and Description iproperties are easy to handle.  But I am stuck on how to access the member name and edit it.  I guessed at some methods, but keep getting errors.

 

Thanks.

 

-Dan

5 REPLIES 5
Message 2 of 6
xiaodong_liang
in reply to: danmorick

Hi,

 

Similar to iPart, the iAssembly is edited through the corresponding Excel table. Here is a small demo on how to create which could be start for you.

 

Public Sub CreateiAssemblyFactory()
    
    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim odef As AssemblyComponentDefinition
    Set odef = oDoc.ComponentDefinition
    
    Dim oFactory As iAssemblyFactory
    Set oFactory = odef.CreateFactory
    
    Dim oWorkSheet As WorkSheet
    Set oWorkSheet = oFactory.ExcelWorkSheet
    
    Dim oCells As Range
    Set oCells = oWorkSheet.Cells
    
    ' Columns...
    oCells.Item(1, 2) = "HANDLE CAP:1:Include/Exclude"
    oCells.Item(1, 3) = "HANDLE CAP:2:Include/Exclude"
    oCells.Item(1, 4) = "LEVER ARM:1:Include/Exclude"
    oCells.Item(1, 5) = "Arbor_Frame:1:Grounding Status"
    oCells.Item(1, 6) = "d75"
    oCells.Item(1, 7) = "d92"
    
    ' Row 1 values...
    oCells.Item(2, 1) = "Arbor_Press-01"
    oCells.Item(2, 2) = "Include"
    oCells.Item(2, 3) = "Include"
    oCells.Item(2, 4) = "Include"
    oCells.Item(2, 5) = "Grounded"
    oCells.Item(2, 6) = "0.0 in"
    oCells.Item(2, 7) = "180.00000"
    
    ' Row 2 values...
    oCells.Item(3, 1) = "Arbor_Press-02"
    oCells.Item(3, 2) = "Include"
    oCells.Item(3, 3) = "Include"
    oCells.Item(3, 4) = "Include"
    oCells.Item(3, 5) = "Grounded"
    oCells.Item(3, 6) = "0.5 in"
    oCells.Item(3, 7) = "90.00000"
    
    ' Row 3 values...
    oCells.Item(4, 1) = "Arbor_Press-03"
    oCells.Item(4, 2) = "Exclude"
    oCells.Item(4, 3) = "Exclude"
    oCells.Item(4, 4) = "Exclude"
    oCells.Item(4, 5) = "Ungrounded"
    oCells.Item(4, 6) = "0.0 in"
    oCells.Item(4, 7) = "180.00000"

    Dim oWB As WorkBook
    Set oWB = oWorkSheet.Parent
    
    oWB.Save
    oWB.Close

End Sub

 

Message 3 of 6
danmorick
in reply to: xiaodong_liang

Xiaodong,

 

Thanks very much for that.  Unfortunately, I have my code as ilogic, not straight VB.NET.  So when I run this I get an error,

"Type 'WorkSheet' is not defined."  Is there a way that you can think of to do this in the ilogic environment?  My member name is always a formula of Part Number and Description iproperties, both of which I have in my table.

 

My alternative, I suppose, is to convert my code to pure vb.net and then proceed...

 

-Dan

Message 4 of 6
xiaodong_liang
in reply to: danmorick

Hi,

 

you could declare the objects of Excel without type. I believe iLogic has import Excel reference, that is why there are some methods under the category Excel. The iLogic code below works well at my side.

 

 
    Dim oDoc As AssemblyDocument
     oDoc = ThisApplication.ActiveDocument
    
    Dim odef As AssemblyComponentDefinition
     odef = oDoc.ComponentDefinition
    
    Dim oFactory As iAssemblyFactory
     oFactory = odef.CreateFactory
    
    Dim oWorkSheet
     oWorkSheet = oFactory.ExcelWorkSheet
    
    Dim oCells
     oCells = oWorkSheet.Cells
    
    ' Columns...
    oCells.Item(1, 2) = "HANDLE CAP:1:Include/Exclude"
    oCells.Item(1, 3) = "HANDLE CAP:2:Include/Exclude"
    oCells.Item(1, 4) = "LEVER ARM:1:Include/Exclude"
    oCells.Item(1, 5) = "Arbor_Frame:1:Grounding Status"
    oCells.Item(1, 6) = "d75"
    oCells.Item(1, 7) = "d92"
    
    ' Row 1 values...
    oCells.Item(2, 1) = "Arbor_Press-01"
    oCells.Item(2, 2) = "Include"
    oCells.Item(2, 3) = "Include"
    oCells.Item(2, 4) = "Include"
    oCells.Item(2, 5) = "Grounded"
    oCells.Item(2, 6) = "0.0 in"
    oCells.Item(2, 7) = "180.00000"
    
    ' Row 2 values...
    oCells.Item(3, 1) = "Arbor_Press-02"
    oCells.Item(3, 2) = "Include"
    oCells.Item(3, 3) = "Include"
    oCells.Item(3, 4) = "Include"
    oCells.Item(3, 5) = "Grounded"
    oCells.Item(3, 6) = "0.5 in"
    oCells.Item(3, 7) = "90.00000"
    
    ' Row 3 values...
    oCells.Item(4, 1) = "Arbor_Press-03"
    oCells.Item(4, 2) = "Exclude"
    oCells.Item(4, 3) = "Exclude"
    oCells.Item(4, 4) = "Exclude"
    oCells.Item(4, 5) = "Ungrounded"
    oCells.Item(4, 6) = "0.0 in"
    oCells.Item(4, 7) = "180.00000"

    Dim oWB
     oWB = oWorkSheet.Parent
    
    oWB.Save
    oWB.Close
Message 5 of 6
danmorick
in reply to: xiaodong_liang

Excellent!  Yes, this is working for me.  Thanks so much for the assistance.

Message 6 of 6
erichter
in reply to: xiaodong_liang

This method works great to change the Excel table, but I am trying to use this to change an entire column of the table (including the active row), and iLogic will not update the model based on the active row of the table. Furthermore, Inventor seems to want to override the table's active row based on the current model state. Unless I open the Excel table again while answering "no" to the prompt to update the table, then save and close the table and answer "yes" to the prompt to update the model. Do you know of a way to force the table to update the model or a workaround that will achieve the same effect?

 

For i = 2 to oFactory.TableRows.Count + 1
oCells.Item(i, 3) = "Text to replace"
Next

 

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

Post to forums  

Autodesk Design & Make Report