Autor
|
Thema: Array duplicates removal (427 mal gelesen)
|
Sylas Mitglied
Beiträge: 322 Registriert: 19.11.2012 Dell Precision T3500 Intel Xeon W3550 @ 3,07 GHz 12 GB RAM CATIA V5 R28
|
erstellt am: 18. Aug. 2022 14:09 <-- editieren / zitieren --> Unities abgeben:
Hello Profis I'm struggling with some part of the macro I'm building, and I was wondering someone could give me a push Generally I've got a list of products each with some components. I'm getting all the components' bodies all together and checking in which product they are in. So, as result I've got an array({Bodies_count},1), where first column is components name, and second is its parents' product name. Next step is in so-called allcatpart to create bodies for 2nd and 1st column of the array, and then assemble component bodies to specific product body. As end effect, I would like to have X Product bodies with assembled Y components' bodies in each X body. I hope I'm clear here My problem is, that the array has many dupicates in second column, since there are many components in product one. The question is: how to remove duplicates from the second column, or at least prevent CATIA from creating multiple "instances" of the Product-Body? Below some snippets from my code: collection names:
Code:
oselection.Search ("(((((FreeStyle.Body + 'Part Design'.Body) + 'Generative Shape Design'.Body) + 'Functional Molded Part'.Body) + 'Functional Molded Part'.Body) & Visibility=Visible),sel") If (Status <> "Normal") Then Exit Sub Else Dim aSelectedElements() ReDim aSelectedElements(0) Dim aNames() As String iSelCounter = oselection.Count ReDim aNames(iSelCounter, 1) Dim i As Integer For i = 1 To oselection.Count Dim sRefString As String Set oSelElement = oselection.Item(i).Value 'oSelection.Item(1).Value sRefString = "!" & oSelElement.Name Set oleafprod = oselection.Item(i).LeafProduct If oleafprod.Parent.Parent.Definition = "DITTO" Then aNames(i, 0) = oleafprod.PartNumber & " - " & oleafprod.DescriptionRef aNames(i, 1) = oleafprod.Parent.Parent.Parent.Parent.PartNumber & " - " & oleafprod.Parent.Parent.Parent.Parent.DescriptionRef Else aNames(i, 0) = oleafprod.Parent.Parent.PartNumber & " - " & oleafprod.DescriptionRef aNames(i, 1) = oleafprod.Parent.Parent.Parent.Parent.PartNumber & " - " & oleafprod.Parent.Parent.Parent.Parent.DescriptionRef End If Set oParent = oleafprod sRefString = oParent.Name & "/" & sRefString Do Set oParent = FUNC_PathToRoot(oParent) sRefString = oParent.Name & "/" & sRefString Loop Until LCase(oParent.Parent.Parent.Name) = "cnext" ReDim Preserve aSelectedElements(UBound(aSelectedElements) + 1) Set aSelectedElements(UBound(aSelectedElements)) = oRootProd.CreateReferenceFromName(sRefString) Next End If
creating bodies: Code:
For j = 1 To UBound(aNames) On Error Resume Next Set oZPBodies = oZP.ReferenceProduct.Parent.Part.Bodies Set oBody2 = oZPBodies.Item(aNames(j, 1)) MyErrNumber = Err.Number On Error GoTo 0 ' Reset error handling If MyErrNumber <> 0 Then GoTo label1 label1: oZPBodies.Add oZPBodies.Item(oZPBodies.Count).Name = aNames(j, 1) Next
I was trying to use error handling to pass by body creation if the body already exists, but it seems not working Probably my fault :P Can anyone advice me how to solve this? Thanks in advance Lucas Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
bgrittmann Moderator Konstrukteur
Beiträge: 11780 Registriert: 30.11.2006 CATIA V5R19
|
erstellt am: 18. Aug. 2022 14:44 <-- editieren / zitieren --> Unities abgeben: Nur für Sylas
Hi Lucas It is not clear for me, what you wanna to archive (maybe show a picture of the structure) Maybe have a look on a dictionary, to storing unique keys. For creating a body with a specific name, here a example: Code: Sub CreateBody(oBodies as Bodies, sBodyName as String) On Error Resume Next if oBodies.Item(sBodyName) is Nothing Then Set oBody = oBodies.Add() oBody.Name = sBodyName end if end Sub
Regards, Bernd ------------------ Warum einfach, wenn es auch kompliziert geht. Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
Sylas Mitglied
Beiträge: 322 Registriert: 19.11.2012 Dell Precision T3500 Intel Xeon W3550 @ 3,07 GHz 12 GB RAM CATIA V5 R28
|
erstellt am: 18. Aug. 2022 15:49 <-- editieren / zitieren --> Unities abgeben:
Hi Bernd As a result, under the "allcatpart" I want to have same assembled bodies structure, as Source product structure is: SOURCE STRUCTURE: MainProduct → Product 1 → part1 → part2 → part3 → Product 2 → part1 → part2 → part3 TARGET STRUCTURE (UNDER "ALLCATPART" PART): → Body1.Name=Product 1.PartNumber & " - " & Product 1.DescriptionRef → assemble1.name=part1.partnumber → body1.name=part1.partnumber → assemble2.name=part2.partnumber → body2.name=part2.partnumber → assemble3.name=part3.partnumber → body3.name=part3.partnumber → Body2.Name=Product 2.PartNumber & " - " & Product 2.DescriptionRef → assemble1.name=part1.partnumber → body1.name=part1.partnumber → assemble2.name=part2.partnumber → body2.name=part2.partnumber → assemble3.name=part3.partnumber → body3.name=part3.partnumber The problem is, that if I have multiple instance of a product1 for an example, then catia creates Body1 for each instance of a product1, but assembles components of this product only under body of the first instance of product1, leaving second body with the same name empty I hope that clears the situation a bit Unfortunately my company security restrictions doesn;t allow my to publicate pictures on any site - sorry Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
bgrittmann Moderator Konstrukteur
Beiträge: 11780 Registriert: 30.11.2006 CATIA V5R19
|
erstellt am: 18. Aug. 2022 16:02 <-- editieren / zitieren --> Unities abgeben: Nur für Sylas
Hi How do you create the allcatpart? Does your script copy the bodies and create the boolean operation, or do you use a build in function? What shall happen if two identical subproducts are present? Shall these bodies assembled in a common body? regards Bernd ------------------ Warum einfach, wenn es auch kompliziert geht. Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
Sylas Mitglied
Beiträge: 322 Registriert: 19.11.2012 Dell Precision T3500 Intel Xeon W3550 @ 3,07 GHz 12 GB RAM CATIA V5 R28
|
erstellt am: 18. Aug. 2022 17:12 <-- editieren / zitieren --> Unities abgeben:
Zitat: Original erstellt von bgrittmann: HiHow do you create the allcatpart? Does your script copy the bodies and create the boolean operation, or do you use a build in function? What shall happen if two identical subproducts are present? Shall these bodies assembled in a common body? regards Bernd
allcatpart is already existing part in catia tree structure which I choose by selectelement3 earlier. Script is copying bodies and paste in without link, assembling bodies too if the product1 occurs second time, same set of bodies should be assembled under another Product-Instance body regards Lucas
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
bgrittmann Moderator Konstrukteur
Beiträge: 11780 Registriert: 30.11.2006 CATIA V5R19
|
erstellt am: 18. Aug. 2022 17:27 <-- editieren / zitieren --> Unities abgeben: Nur für Sylas
Hi Lucas So my (previous posted) example code should help you (maybe change it to a function to get the body by name). Be aware: - your search also find empty/in boolean operation used/hidded bodies
- if you use the partnumber of a subproduct and not the instance name it could be hard to get the right body for the boolean operation
regards, Bernd ------------------ Warum einfach, wenn es auch kompliziert geht. Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
| Anzeige.:
Anzeige: (Infos zum Werbeplatz >>)
|