In the example below , I want to give a name to a subassembly or subpart inside of the top assembly? Is anybody has any idea about it?
Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument Dim oDef As AssemblyComponentDefinition oDef = oDoc.ComponentDefinition ' Get the top level occurrence of an assembly Dim oOcc1 As ComponentOccurrence oOcc1 = oDef.Occurrences.Item(1) Dim oOccA As String oOccA = oOcc1.Name Dim oOcc2 As ComponentOccurrence oOcc2 = oDef.Occurrences.Item(7) Dim oOccF As String oOccF = oOcc2.Name
Solved! Go to Solution.
Solved by Sergio.D.Suárez. Go to Solution.
Solved by Sergio.D.Suárez. Go to Solution.
Hi, try this line, change the names to your liking and with care
Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument Dim oDef As AssemblyComponentDefinition oDef = oDoc.ComponentDefinition Dim oOcc1 As ComponentOccurrence oOcc1 = oDef.Occurrences.Item(1) Dim oOccA As String oOccA = oOcc1.Name Dim oOcc2_1 As ComponentOccurrence 'Set sheel course 1_4 Check item oOcc2_1 = oDef.Occurrences.Item(7) Dim oOccF_1 As String oOccF_1 = oOcc2_1.Name Dim oOcc2 As ComponentOccurrence 'Set sheel course 1_4_1 Check item oOcc2 = oOcc2_1.Definition.Document.ComponentDefinition.Occurrences.Item(1) Dim oOccF As String oOccF = oOcc2.Name MessageBox.Show( oOccF_1 , "Title") ' Check item MessageBox.Show( oOccF , "Title") ' Check item
Regards!!!!
PD: You must keep in mind that with this method, you should not order the components because they will change places and the rule will give errors
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn
Dear yuvilo_;
When I add that rules below, it gives error as photo below
Dim oOcc2 As ComponentOccurrence 'Set sheel course 1_4_1 Check item oOcc2 = oOcc2_1.Definition.Document.ComponentDefinition.Occurrences.Item(1) Dim oOccF As String oOccF = oOcc2.Name
Try this rule only. Set if changing the element you can identify the piece or sub-assembly, then, if the dialog box is deleted, and then cut and paste them in your rule
On Error Resume Next Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument Dim oDef As AssemblyComponentDefinition oDef = oDoc.ComponentDefinition Dim oOcc1 As ComponentOccurrence oOcc1 = oDef.Occurrences.Item(1) Dim oOccA As String oOccA = oOcc1.Name Dim oOcc2_1 As ComponentOccurrence 'Set sheel course 1_4 Check item oOcc2_1 = oDef.Occurrences.Item(6) Dim oOccF_1 As String oOccF_1 = oOcc2_1.Name MessageBox.Show( oOccF_1 , "Title") ' Check item Dim oOcc2 As ComponentOccurrence 'Set sheel course 1_4_1 Check item oOcc2 = oOcc2_1.Definition.Document.ComponentDefinition.Occurrences.Item(1) Dim oOccF As String oOccF = oOcc2.Name MessageBox.Show( oOccF , "Title") ' Check item
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn
Dear yuvilo_ ;
I am grateful for your helps.
it is only working , if i add "On Error Resume Next" . But the error still exists.
Do I have any problem with that?
Why it gives that kind of error?
the instruction on the error summarizes then continues the rule if an error is found, it does not stop at the error, place it so you can see the dialog box, and in that way the element is being modified until the piece is identified. if you still can not find shared files here to see them and accommodate them
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn
Dear yuvilo_;
I attached it. you may see it. After delete "On Error Resume Next" in the rule , try to pass between 1 and 2 i described in the photo. Then it will give error.
Hi how are you, I have tried this code, I put the message boxes to help me find the error, then you remove them, there are recognized components that you initially needed
Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument Dim oDef As AssemblyComponentDefinition oDef = oDoc.ComponentDefinition Dim oOcc1 As ComponentOccurrence 'Left head name oOcc1 = oDef.Occurrences.Item(1) Dim oOccA As String oOccA = oOcc1.Name MessageBox.Show(oOccA, "Left head name") Dim oOcc3 As ComponentOccurrence 'Shell course_1_4 name oOcc3 = oDef.Occurrences.Item(6) Dim oOccC As String oOccC = oOcc3.Name MessageBox.Show(oOccC, "Shell course_1_4 name") Dim oOcc4 As ComponentOccurrence 'Shell course_2_4 name oOcc4 = oDef.Occurrences.Item(7) Dim oOccD As String oOccD = oOcc4.Name MessageBox.Show(oOccD, "Shell course_2_4 name") Dim oOcc4_1 As ComponentOccurrence 'Shell course_1_4_1 name oOcc4_1 = oOcc3.Definition.Document.ComponentDefinition.Occurrences.Item(1) Dim oOccD_1 As String oOccD_1 = oOcc4_1.Name MessageBox.Show( oOccD_1,"Shell course_1_4_1 name")
On the other hand, it controls the instruction "if then else end if", it should be seen as a continuation
If Number_of_shell_course > 1 Then Component.IsActive(oOccD) = False Else Component.IsActive(oOccD) = True End If If Number_of_shell_course > 1 Then Component.IsActive(oOccD_1) = True Else Component.IsActive(oOccD_1) = False End If
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn
Ok , thank you. It works well now. I may need for your further help ongoing times
no problem, if I can help you with pleasure I will, remember that I have learned only and know basic things, I am not like many who are around here who are great teachers, if I can not solve something surely they can do it. If the comment served you mark it as a solution, we keep in touch. regards!!
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn
Can't find what you're looking for? Ask the community or share your knowledge.