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: 

NEED HELP ... How to change a part parameters in Sub-Assembly.

9 REPLIES 9
Reply
Message 1 of 10
yudhistira
2249 Views, 9 Replies

NEED HELP ... How to change a part parameters in Sub-Assembly.

Does anyone know how to handle this?

I have design tree like this:

 

Main Assembly

L Sub Assembly1

L Sub Assembly 2

    L Sub Assembly 3

        L part 1

 

in part i have a parameter name ("Panjang")... does anyone know how to control "Panjang"?. I cannot access a part parameter in Sub-assembly.

Please help me with this trouble. Thank You very much.

 

best regards,

 

 

Yudhistira Hasannudin

Hasannudin Bersaudara Maju

 

Email    : yudhidesign@yahoo.co.id

Web      : http://www.hbm-engineering.webs.com/

                http://trainingcad.webs.com/

                http://cadhunter.webs.com/

 

HBM Training Center | Indonesian Professional CAD/CAM/CAE Training and Certification Center
http://www.hbm-training.com/
============================================================
If my solution can answer your question, please push
"Accept As Solution" button in below ....
9 REPLIES 9
Message 2 of 10
Mike.Wohletz
in reply to: yudhistira

The attached  code uses a tree view in an Assembly and you can dig all the way to the bottom of the assembly. If you click on the item in the tree view it will populate a list box with the parameters. With a little work of possibly changing this list bog to a gridview and adding the proper units to be displayed this will allow you to change the parameters as deep as you want to go. 

 

 

  Public Sub treeViewSample()
        If ThisApplication.ActiveDocument.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
            For Each oDoc As Document In ThisApplication.ActiveDocument.AllReferencedDocuments
                If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
                    Dim oAssemblyNode As New TreeNode
                    oAssemblyNode.Tag = oDoc.FullDocumentName
                    oAssemblyNode.Text = GetFileNameFromPath(oDoc.FullDocumentName)
                    oAssemblyNode.Nodes.Add("*DummyNode*") ' we want the + to show up but don't need to load all the files yet
                    TreeView1.Nodes.Add(oAssemblyNode)
                Else
                    Dim oPartNode As New TreeNode
                    oPartNode.Tag = oDoc.FullDocumentName
                    oPartNode.Text = GetFileNameFromPath(oDoc.FullFileName)
                    TreeView1.Nodes.Add(oPartNode)
                End If
            Next
        End If
    End Sub

    Private Sub TreeView1_BeforeExpand(sender As Object, e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView1.BeforeExpand
        'when the + is clicked we will load all the sub nodes if it is not done yet
        If e.Node.Nodes.Item(0).Text = "*DummyNode*" Then
            e.Node.Nodes.Clear()
            For Each oDoc As Document In ThisApplication.Documents.ItemByName(e.Node.Tag.ToString).AllReferencedDocuments
                If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
                    Dim oAssemblyNode As New TreeNode
                    oAssemblyNode.Tag = oDoc.FullDocumentName
                    oAssemblyNode.Text = GetFileNameFromPath(oDoc.FullDocumentName)
                    oAssemblyNode.Nodes.Add("*DummyNode*")
                    e.Node.Nodes.Add(oAssemblyNode)
                Else
                    Dim oPartNode As New TreeNode
                    oPartNode.Tag = oDoc.FullDocumentName
                    oPartNode.Text = GetFileNameFromPath(oDoc.FullFileName)
                    e.Node.Nodes.Add(oPartNode)
                End If
            Next
        End If
    End Sub

    Private Sub TreeView1_AfterSelect(sender As Object, e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
        'when the item is clicked we will get the parameters and display them in a list box
        ListBox1.Items.Clear()
        Dim SelectedItem As Object = ThisApplication.Documents.ItemByName(e.Node.Tag.ToString)
        For Each oParam As Parameter In SelectedItem.ComponentDefinition.Parameters
            ListBox1.Items.Add(oParam.Name & vbTab & oParam.ModelValue)

        Next
    End Sub

    Public Function GetFileNameFromPath(ByVal path As String) As String
        Try
            Return path.Substring(path.LastIndexOf("\") + 1)
        Catch ex As Exception
            ' error
            Return ""
        End Try

    End Function

 

Message 3 of 10
amitnkukanur
in reply to: Mike.Wohletz

But how to change the parameters. Here we are fetching the data...

Senior Software Engineer
Message 4 of 10
Mike.Wohletz
in reply to: yudhistira

Message 5 of 10
VGonsalves
in reply to: Mike.Wohletz

Hi Mike

 

I am currently using Inventor Pro 2012 and I am trying to use the macro you have created.

 

I copied the above code and pasted it in the Visual Basic environment of Inventor as a new Module. But I keep getting heaps of errors. Following are the lines that a showing up in red

"For Each oDoc As Document In ThisApplication.ActiveDocument.AllReferencedDocuments"

"Private Sub TreeView1_BeforeExpand(sender As Object, e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView1.BeforeExpand"

"e.Node.Nodes.Clear()
            For Each oDoc As Document In ThisApplication.Documents.ItemByName(e.Node.Tag.ToString).AllReferencedDocuments"

"Private Sub TreeView1_AfterSelect(sender As Object, e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect"

"ListBox1.Items.Clear()
        Dim SelectedItem As Object = ThisApplication.Documents.ItemByName(e.Node.Tag.To?String)
        For Each oParam As Parameter In SelectedItem.ComponentDefinition.Parameters"

"Return path.Substring(path.LastIndexOf("\") + 1)
        Catch ex As Exception
            ' error
            Return ""
        End Try"

I do not know how to edit them or troubleshoot so I need to ask for help. If I hit the run button the first red line gets highlighted and I get an error box saying "Compile error: Syntax error"

 

I hope you can help me understand the errors and also use the macro.

 

Thank you for reading my request

Message 6 of 10
amitnkukanur
in reply to: yudhistira

Hi vishgon,

 

Basically this is a VB.net part of code,it doesn't work as macro. Can you debrief what are you trying to achieve

 

 

rgds

Amit

Senior Software Engineer
Message 7 of 10
VGonsalves
in reply to: amitnkukanur

Hi Amit

 

Thanks for your reply. Actually I read this post and thought that I could use it to suit my needs. I am actually trying to mimics the iproperties dialog box with only the stuff that I need, plus have a couple of parameters in there. So one dialog box that allows me access to the part's iproperties (few built-in ones and all custom ones) and parameters while in assembly mode and not part edit mode.

 

I have created a iLogic form to do this but you have to be in part edit mode so it is very limited and also I cannot pick a group of objects and modify the iproperties at the same time using that dialog box.

 

I hope this gives you some understanding in regards to what I ultimately am trying to achieve.

 

Regards

Vishal

Message 8 of 10
Mike.Wohletz
in reply to: VGonsalves

Vishal

The code that I had posted will do just what you are looking for but this is not going to work from VBA or iLogic. If you are looking to do this in iLogic you will need to work with the files a little different due to application limits. I would look at this for a good idea on how to grab this info from a selected item. The real challenge you will have is working with this information in a iLogic form. I would suggest doing this in .NET but that is just my opinion. 

 

Message 9 of 10
amitnkukanur
in reply to: yudhistira

Hello Vishal,

 

 

I Understand the project objective well. However the solution posted here works perfectly without any issues in .NET, its a .NET part of Code. Its a cumbersome task to  make the same application work for ILogic or VBA macro. I suggest you go with .NET coding, but if situation demands ILogic or VBA Macro then its long process.

 

 

regards

Amit

Senior Software Engineer
Message 10 of 10
VGonsalves
in reply to: Mike.Wohletz

Mike

 

Thanks for replying. To start with I have no idea when it comes to VB.Net so I guess my quest ends here. Plus we do not have access to any additional software at work so I will not be able to use your code Smiley Sad. My current implementaion is a two step approach, one using Curtis's code to look inside a part file and the second is an ilogic form run after getting into part edit mode. Yes I have seen Curtis's code, I visit his website frequently.

 

I will try your code at home if all I have to do is copy it into the editor.

 

Thank you

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

Post to forums  

Autodesk Design & Make Report