Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

CATIA VBA Geoset/Parent Name Extraction 3

Status
Not open for further replies.

JohnWass

Aerospace
Apr 12, 2022
4
US
thread560-438183

Below is working great for point extraction, name, and parent name, so long as there is no child geo-sets within a geoset. I have sub-parent geoset names (children) that I need to identify as well in an adjacent column. Is this possible?

Code:
Sub CATMain()

    Set objexcel = CreateObject("Excel.Application")
    
    objexcel.Visible = True
    
    Set objWorkbook = objexcel.Workbooks.Add()
    
    Set objsheet1 = objWorkbook.Sheets.Item(1)
    
    objsheet1.Name = "Points_Coordinates"
    
    Dim coords(2) As Variant
    
    Set Selection = CATIA.ActiveDocument.Selection
    
    Selection.Search "( CATPrtSearch.Point),all"
    
    For I = 1 To Selection.Count
        
        Set Element = Selection.Item(I)
        
        Set Point = Element.Value
        
        Point.GetCoordinates (coords)
                   
        objsheet1.cells(I + 1, 1).Value = Point.Name
        
        objsheet1.cells(I + 1, 2).Value = coords(0)
        
        objsheet1.cells(I + 1, 3).Value = coords(1)
        
        objsheet1.cells(I + 1, 4).Value = coords(2)
        
        'objsheet1.cells(I + 1, 5).Value = Element.Name
                        
        'this is for non-isolated Points
        Set ParentObject = Point.Parent
        Do
            If TypeName(ParentObject) = "HybridBody" Or TypeName(ParentObject) = "Body" Then
                objsheet1.cells(I + 1, 5).Value = ParentObject.Name
                Exit Do
            Else
                Set ParentObject = ParentObject.Parent
            End If
            'safe check
            If TypeName(ParentObject) = "Part" Then
                Exit Do 'you've went to far up and reached the Part itself.
            End If
        Loop
        
        'this is for isolated points
        If objsheet1.cells(I + 1, 5).Value = "" Then
        
            bFound = False
            Set oPart = CATIA.ActiveDocument.Part
            'temporarily rename the point so the proper point is retrieved.
            tmpPointName = "tmpPoint." & I
            Point.Name = tmpPointName
            For ix = 1 To oPart.HybridBodies.Count
                Set oMyHBody = oPart.HybridBodies.Item(ix)
                For jx = 1 To oMyHBody.HybridShapes.Count
                    Set oHShape = oMyHBody.HybridShapes.Item(jx)
                    If oHShape.Name = tmpPointName Then
                        'this is my Point. get the parent's name
                        objsheet1.cells(I + 1, 5).Value = oMyHBody.Name
                        bFound = True
                        Exit For
                    End If
                Next
                If bFound Then Exit For
            Next
 
Replies continue below

Recommended for you

this code works through selection search i.e it finds all points, no matter where in tree (level) they reside.
so apart from the parent geo-set name, you also wish to get the name of the geo-set higher up?...

regards,
LWolf
 
Unfortunately yes. After some more digging, I've found that the issue resides in the points being isolated. I can call up each geoset parent name with the parent method, but only when I change a point from an explicit to a coordinate point. Is there a selectiom loop I could use to change all my points from explicit to coordinate points? I have too many hours in my dataset at this point to start over.
 
I'd do it little bit different: just set define work object on the point, that will put the "line" on the set it is located in :)
no need for parent-stuff, so it will work for both types. Then you can walk up to the higher level by parent method

Code:
Set oPart = CATIA.ActiveDocument.Part
oPart.InWorkObject = Point
Set myHybridBody = oPart.InWorkObject
set myParentBody = myHybridBody.parent

regards,
LWolf
 
I believe the source of the problem is that datum geometry (i.e. isolated points) can be directly valuated with Knowledgeware formulas and relations and thus acts like Parameter class object. So when you call .Parent on it a Parameters collection is retrieved.

What you can do is explicitly request access to isolated point on mechanical modeler interface:

Code:
dim psp as PspWorkbench
Set psp = CATIA.ActiveDocument.Product.GetTechnologicalObject("PspWorkbench")

Dim pointItf
Set pointItf = psp.GetInterface("CATIAHybridShape", point)
msgbox pointitf.Parent.Parent.Name
 
Thank you both for taking the time to assist, but I'm struggling to incorporate either solution. The inworkobject path still seems to skip all geoset parents unless there is only one parent for the geoset. And having trouble compiling the latter sample. Got my references sorted out, but getting an object req error on setting pointItf.
 
The inworkobject path still seems to skip all geoset parents unless there is only one parent for the geoset

InWorkObject activates closest geoset (bottom level) so you're able to iterate right to the top. Another key is that accessing .Parent actually returns a collection that contains current object, not it's actual parent. So what you want to do is to call .Parent.Parent

Code:
Function GetPointPath(partRoot, pointFeature)
    Dim current, path
    partRoot.InWorkObject = pointFeature
    set current = partRoot.InWorkObject
    path = pointFeature.Name
    do while TypeName(current) <> "Part"
        path = current.Name + "/" + path
        set current = current.Parent.Parent
    loop
    GetPointPath = path
End Function
 
That made it click! Many thanks for the explanation; and more so the learning opportunity. I'm able to grow my tree to my heart's content now.
 
worth to mention is that the same/similar function (to GetPointPath) could be used to get hold of the current part :)
quite often I noticed I need to find the part hosting my object, thus I have a function GetPartFromObject returning the part object.

regards,
LWolf
 
quite often I noticed I need to find the part hosting my object, thus I have a function GetPartFromObject returning the part object

I also used to add object to Selection and call
Code:
.LeafProduct.ReferenceProduct.Parent
to get containing document.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top