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/
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
But how to change the parameters. Here we are fetching the data...
I have posted the answer to this in this forum:
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
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
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.
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
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 . 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