×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Copy & Paste published elements in context
2

Copy & Paste published elements in context

Copy & Paste published elements in context

(OP)
I have one level assembly with multiple parts and their instances on different positions. Parts already have published elements (lines and axis systems) that are needed to be copied in (empty) part called "Positions" which is in the in same assembly, so the position of copied elements doesn't change, and also their name should be same as in source part.
I have very very basic skills on programming, so I searched for a similar macro, but couldn't find it ... does anyone have something similar that I could use for a start?

RE: Copy & Paste published elements in context

i would suggest to develop your programming skills one step at a time.

first make a script to identify the 'active document' and make sure it s a product, if not message the user and exit

Second script would be to add an new part in your product with the proper name.

Third script would be to find the first part in your assembly and identify (select) the element to copy.

Fourth would be the copy / paste.

Fifth would be the keep the name requirement.

Finally modify your script to navigate the assembly for the source part.

show us your progress and tell us the challenge you have, you'll find many people ready to help.

Many user could learn from this, so don't be shy to share.

before you do that, go check the v5automation.chm file on your catia install folder (and read as many script as you can) and the catia portable script center (and read more script) ...

Waiting for your code of step 1 and 2, this should not be too long.

Eric N.
indocti discant et ament meminisse periti

RE: Copy & Paste published elements in context

(OP)
Here is code, handling first two steps ...

CODE -->

Sub CATMain()
    Dim rootProduct As Product
    Set rootProduct = CATIA.ActiveDocument.Product
    
    If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1 Then
        Debug.Print rootProduct.Name & " Is NOT Product!"
    Exit Sub
   End If
        Debug.Print rootProduct.Name & " Is Product!"
   Dim newPart As Product
   Set newPart = rootProduct.Products.AddNewComponent("Part", "Positions")
   
End Sub 

Now I'm a bit confused how to properly set search parameters, so it would find and select only published elements in parts

RE: Copy & Paste published elements in context

Good.

Before you get to the publication, you should get the first part.

check in your rootProduct.Products



Once you have the proper object, you'll find the publications

Eric N.
indocti discant et ament meminisse periti

RE: Copy & Paste published elements in context

(OP)
I hope I understood correctly, as you can see in code below, I used For loop to run trough all parts and their instances in assembly, and for now just output part's names when loop is running(for check).
Additional question at this point is, if I can limit parts used in FOR loop to only visible parts?

CODE -->

Sub CATMain()
    Dim rootProduct As Product
    Set rootProduct = CATIA.ActiveDocument.Product
    
    If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1 Then
        Debug.Print rootProduct.Name & " Is NOT Product!"
    Exit Sub
    End If
    
    Debug.Print rootProduct.Name & " Is Product!"
    
    Dim newPart As Product
    Set newPart = rootProduct.Products.AddNewComponent("Part", "Positions5")
   
    Dim subProduct As Product
    For i = 1 To rootProduct.Products.Count
        Set subProduct = rootProduct.Products.Item(i)
        Debug.Print rootProduct.Products.Item(i).Name
    Next   
End Sub 

RE: Copy & Paste published elements in context

your FOR loop will go from 1 to rootProduct.Products.Count visible or not

What you can do is check if rootProduct.Products.Item(i) is visible or not

the visibility is given by selection.VisProperties

CATIA.ActiveDocument.Selection is the selection, once you define the selection object you can add, remove, copy, paste...

Can you debug.Print only visible instances?

Eric N.
indocti discant et ament meminisse periti

RE: Copy & Paste published elements in context

(OP)
what I'm trying now is to filter all parts inside FOR loop with IF, if current part is visible or not, but I'm heaving a bit trouble to test this VisProperties correctly, as you will notice in my code:

CODE -->

Sub CATMain()
    Dim rootProduct As Product
    Set rootProduct = CATIA.ActiveDocument.Product
    
    If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1 Then
        Debug.Print rootProduct.Name & " Is NOT Product!"
    Exit Sub
    End If
    
    Debug.Print rootProduct.Name & " Is Product!"
    
    Dim newPart As Product
    Set newPart = rootProduct.Products.AddNewComponent("Part", "Positions")
   
    Dim subProduct As Product
    For i = 1 To rootProduct.Products.Count
        Set subProduct = rootProduct.Products.Item(i)
        If subProduct.VisProperties = True Then
            Debug.Print subProduct.Name & " IS visible!"
        Else
            Debug.Print subProduct.Name & " is NOT visible!"
        End If
    Next
End Sub 

RE: Copy & Paste published elements in context

VisProperties belongs to selection object not to product object

Eric N.
indocti discant et ament meminisse periti

RE: Copy & Paste published elements in context

check v5automation.chm about selection.visproperty

Eric N.
indocti discant et ament meminisse periti

RE: Copy & Paste published elements in context

ok it's a bit tricky the first time so I'll give you that one

CODE --> CATVBA

Sub CATMain()
    Dim rootProduct As Product
    Set rootProduct = CATIA.ActiveDocument.Product
    
    If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1 Then
        Debug.Print rootProduct.Name & " Is NOT Product!"
    Exit Sub
    End If
    
    Debug.Print rootProduct.Name & " Is Product!"
    
    Dim newPart As Product
    Set newPart = rootProduct.Products.AddNewComponent("Part", "Positions")
   
    Dim oSel As Selection
    Dim vp As VisPropertySet
    
    
    For i = 1 To rootProduct.Products.Count
        Set Instance = rootProduct.Products.Item(i)
        If isVisible(Instance) Then
            Debug.Print (Instance.Name & " is visible")
        Else
            Debug.Print (Instance.Name & " is NOT visible")
        End If
    Next
End Sub

Function isVisible(ByRef object As Variant) As Boolean
    CATIA.ActiveDocument.Selection.Clear
    CATIA.ActiveDocument.Selection.Add object
    
    Dim vp As VisPropertySet
    Dim showstate As CatVisPropertyStatus
    Set vp = CATIA.ActiveDocument.Selection.VisProperties
    vp.GetShow showstate
    
    result = True
    
    If showstate = catVisPropertyNoShowAttr Then result = False
    
    CATIA.ActiveDocument.Selection.Clear
    
    isVisible = result
End Function 

I create a function that return true or false is the element I give to the function is visible.

so first step I loop the product for subproduct (instances)

I get the instance object and give it to the function

the function clear the selection, then add the instance to the selection, then check its visibility and finally return the Boolean

Ok now you have to select the element you want to copy.


Eric N.
indocti discant et ament meminisse periti

RE: Copy & Paste published elements in context

There is also something tricky about the copy paste in context with VBA

Manually, if the "blue level" is the root product you cannot copy geometry elements but only product elements (instances...)

you have to make the part (not the instance) the "blue level" in order to do the copy/paste.

Well in VBA you do the copy paste with the root product as "blue level"

that's the ay it is.

Waiting for your code...


Eric N.
indocti discant et ament meminisse periti

RE: Copy & Paste published elements in context

(OP)
I managed to implement show/hide state test in this way:

CODE -->

Sub CATMain()
    Dim rootProduct As Product
    Set rootProduct = CATIA.ActiveDocument.Product
    
    If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1 Then
        Debug.Print rootProduct.Name & " Is NOT Product!"
    Exit Sub
    End If
    
    Debug.Print rootProduct.Name & " Is Product!"
    
    Dim newPart As Product
    Set newPart = rootProduct.Products.AddNewComponent("Part", "Positions")
   
    Dim subProduct As Product
    Dim oSel As Selection
    Set oSel = CATIA.ActiveDocument.Selection
    oSel.Clear
    
    For i = 1 To rootProduct.Products.Count
        Set subProduct = rootProduct.Products.Item(i)
        oSel.Add rootProduct.Products.Item(i)
        
        Dim showstate As CatVisPropertyShow
        Set visProperties1 = CATIA.ActiveDocument.Selection.VisProperties
        visProperties1.GetShow showstate

        If showstate < 1 Then
            Debug.Print subProduct.Name & " IS visible!"
        Else
            Debug.Print subProduct.Name & " is NOT visible!"
        End If
        oSel.Clear
        
        Next      
End Sub 
comments please, if there should be something done differently...

RE: Copy & Paste published elements in context

(OP)
Would be better to use visibility test as function or subroutine like you did? I guess I will need to use selection for selecting elements that I need to copy from parts and instances?

RE: Copy & Paste published elements in context


yep you need selection for copy / paste but it's not incompatible.

did you notice that your positions.1 instance is in the loop? how can you solve that?

Eric N.
indocti discant et ament meminisse periti

RE: Copy & Paste published elements in context

(OP)
Here is another IF loop added comparing names to added part called Positions in my case ...

CODE -->

Sub CATMain()
    Dim rootProduct As Product
    Set rootProduct = CATIA.ActiveDocument.Product
    
    If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1 Then
        Debug.Print rootProduct.Name & " Is NOT Product!"
    Exit Sub
    End If
    
    Debug.Print rootProduct.Name & " Is Product!"
    
    Dim newPart As Product
    Set newPart = rootProduct.Products.AddNewComponent("Part", "Positions")
   
    Dim oSel As Selection
    Dim vp As VisPropertySet
    
    
    For i = 1 To rootProduct.Products.Count
        Set instance = rootProduct.Products.Item(i)
        If isVisible(instance) Then
            If instance.Name = newPart.Name Then
                Debug.Print (instance.Name & " This is Positions part!")
            Else
            Debug.Print (instance.Name & " IS visible")
            End If
        Else
            Debug.Print (instance.Name & " is NOT visible")
        End If
    Next
End Sub

Function isVisible(ByRef object As Variant) As Boolean
    CATIA.ActiveDocument.Selection.Clear
    CATIA.ActiveDocument.Selection.Add object
    
    Dim vp As VisPropertySet
    Dim showstate As CatVisPropertyStatus
    Set vp = CATIA.ActiveDocument.Selection.VisProperties
    vp.GetShow showstate
    
    result = True
    
    If showstate = catVisPropertyNoShowAttr Then result = False
    
    CATIA.ActiveDocument.Selection.Clear
    
    isVisible = result
End Function 

RE: Copy & Paste published elements in context

that's one solution.

I would have made the count of product before adding the position part like :

CODE --> CATVBA

nbOfInstanceBeforeAddingPart = rootProduct.Products.Count

dim newpart...
set newpart...

for i = 1 to nbOfInstanceBeforeAddingPart 

Can you post a picture of the tree structure showing the publication and eventually the geometry to be copied?

Did you manage to select your geometry? is you geometry always the same name in the same geometricalset? or the only way to find the geometry is from the publication?

Eric N.
indocti discant et ament meminisse periti

RE: Copy & Paste published elements in context

(OP)
Here is code with part and instances count before adding new part called Positions:

CODE -->

Sub CATMain()
    Dim rootProduct As Product
    Set rootProduct = CATIA.ActiveDocument.Product
    
    If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1 Then
        Debug.Print rootProduct.Name & " Is NOT Product!"
    Exit Sub
    End If
    
    Debug.Print rootProduct.Name & " Is Product!"
    
    Dim PsrtsCount As Integer
    PartsCount = rootProduct.Products.Count
    
    Dim newPart As Product
    Set newPart = rootProduct.Products.AddNewComponent("Part", "Positions")
   
    Dim oSel As Selection
    Dim vp As VisPropertySet
    
    
    For i = 1 To PartsCount
        Set instance = rootProduct.Products.Item(i)
        If isVisible(instance) Then
            If instance.Name = newPart.Name Then
                Debug.Print (instance.Name & " This is Positions part!")
            Else
            Debug.Print (instance.Name & " IS visible")
            End If
        Else
            Debug.Print (instance.Name & " is NOT visible")
        End If
    Next
End Sub

Function isVisible(ByRef object As Variant) As Boolean
    CATIA.ActiveDocument.Selection.Clear
    CATIA.ActiveDocument.Selection.Add object
    
    Dim vp As VisPropertySet
    Dim showstate As CatVisPropertyStatus
    Set vp = CATIA.ActiveDocument.Selection.VisProperties
    vp.GetShow showstate
    
    result = True
    
    If showstate = catVisPropertyNoShowAttr Then result = False
    
    CATIA.ActiveDocument.Selection.Clear
    
    isVisible = result
End Function 

Here is Tree structure of my parts, and all parts are created from template part (new from), and in this case it already has published elements like axis system and line. It is important that copied axis system has same name as source part.

RE: Copy & Paste published elements in context

file from a temple is a good idea, it will make the selection easier...

your code still don't do the selection of the element for copy...it should not be that hard...

Eric N.
indocti discant et ament meminisse periti

RE: Copy & Paste published elements in context

(OP)
For selecting publications, I first count them and then make selection trough FOR loop, I hope I access to publications of each part correctly, please comment if it should be done differently ...

CODE -->

Sub CATMain()
    Dim rootProduct As Product
    Set rootProduct = CATIA.ActiveDocument.Product
    
    If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1 Then
        Debug.Print rootProduct.Name & " Is NOT Product!"
    Exit Sub
    End If
    
    Debug.Print rootProduct.Name & " Is Product!"
    
    Dim PartsCount As Integer
    PartsCount = rootProduct.Products.Count
        
    Dim newPart As Product
    Set newPart = rootProduct.Products.AddNewComponent("Part", "Positions")

    Dim vp As VisPropertySet
        
    For i = 1 To PartsCount
        Set instance = rootProduct.Products.Item(i)
        If isVisible(instance) Then
            Debug.Print (instance.Name & " IS visible")
            Dim publCount As Integer
            publCount = rootProduct.Products.Item(i).Publications.Count
            
            Dim selectedEL As Selection
            Set selectedEL = CATIA.ActiveDocument.Selection
            selectedEL.Clear
                                    
            For j = 1 To publCount
                Set publishedEL = rootProduct.Products.Item(i).Publications.Item(j)
                selectedEL.Add publishedEL
                Debug.Print (rootProduct.Products.Item(i).Publications.Item(j).Name & " published element is added to selection")
            Next
        Else
            Debug.Print (instance.Name & " is NOT visible")
        End If
    Next
End Sub

Function isVisible(ByRef object As Variant) As Boolean
    CATIA.ActiveDocument.Selection.Clear
    CATIA.ActiveDocument.Selection.Add object
    
    Dim vp As VisPropertySet
    Dim showstate As CatVisPropertyStatus
    Set vp = CATIA.ActiveDocument.Selection.VisProperties
    vp.GetShow showstate
    
    result = True
    
    If showstate = catVisPropertyNoShowAttr Then result = False
    
    CATIA.ActiveDocument.Selection.Clear
    
    isVisible = result
End Function 

RE: Copy & Paste published elements in context

(OP)
I'm trying to add also copy/paste of selected elements, and I have a bit of a problem "targeting" my newPart correctly to paste elements in it

CODE -->

Sub CATMain()
    Dim rootProduct As Product
    Set rootProduct = CATIA.ActiveDocument.Product
    
    If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1 Then
        Debug.Print rootProduct.Name & " Is NOT Product!"
    Exit Sub
    End If
    
    Debug.Print rootProduct.Name & " Is Product!"
    
    Dim PartsCount As Integer
    PartsCount = rootProduct.Products.Count
        
    Dim newPart As Product
    Set newPart = rootProduct.Products.AddNewComponent("Part", "Positions")
    

    Dim vp As VisPropertySet
        
    For i = 1 To PartsCount
        Set instance = rootProduct.Products.Item(i)
        If isVisible(instance) Then
            Debug.Print (instance.Name & " IS visible")
            Dim publCount As Integer
            publCount = rootProduct.Products.Item(i).Publications.Count
            
            Dim selectedEL As Selection
            Set selectedEL = CATIA.ActiveDocument.Selection
            selectedEL.Clear
                                    
            For j = 1 To publCount
                Set publishedEL = rootProduct.Products.Item(i).Publications.Item(j)
                selectedEL.Add publishedEL
                Debug.Print (rootProduct.Products.Item(i).Publications.Item(j).Name & " published element is added to selection")
                'Debug.Print newPart.Name
                selectedEL.Copy
                selectedEL.Clear
                selectedEL.Add newPart
                selectedEL.PasteSpecial ("CATPrtResultWithOutLink")
                selectedEL.Clear
            Next
        Else
            Debug.Print (instance.Name & " is NOT visible")
        End If
    Next
End Sub

Function isVisible(ByRef object As Variant) As Boolean
    CATIA.ActiveDocument.Selection.Clear
    CATIA.ActiveDocument.Selection.Add object
    
    Dim vp As VisPropertySet
    Dim showstate As CatVisPropertyStatus
    Set vp = CATIA.ActiveDocument.Selection.VisProperties
    vp.GetShow showstate
    
    result = True
    
    If showstate = catVisPropertyNoShowAttr Then result = False
    
    CATIA.ActiveDocument.Selection.Clear
    
    isVisible = result
End Function 

RE: Copy & Paste published elements in context

newpart is a product type, you cannot paste geometry on a product part, you need to have the paste target inside newpart.

newPart is the instance (Product)
newPart.ReferenceProduct is the reference product of the instance (Product)
newPart.ReferenceProduct.Parent is the document supporting the reference product (PartDocument)
newPart.ReferenceProduct.Parent.Part is the part of the document (Part)

inside this part you can create a geometricalSet if you want:

CODE --> CATVBA

Dim targetpart As Part
Set targetpart = newPart.ReferenceProduct.Parent.Part

Dim geomSetTarget As HybridBody
Set geomSetTarget = targetpart.HybridBodies.Add
geomSetTarget.Name = "Scripted External Reference" 

Eric N.
indocti discant et ament meminisse periti

RE: Copy & Paste published elements in context

(OP)
So here is code, which copies all published elements from visible parts and their instances in assembly, creates new part, in this case called "Positions", and pastes elements in it. For now it works only with one level assembly.

Special thanks to itsmyjob for guidance&help!

CODE -->

Sub CATMain()
    Dim rootProduct As Product
    Set rootProduct = CATIA.ActiveDocument.Product
    
    If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1 Then     'product/part check
        MsgBox rootProduct.Name & " Is NOT Assembly!"
    Exit Sub
    End If
    
    'Debug.Print rootProduct.Name & " Is Product!"
    
    Dim PartsCount As Integer
    PartsCount = rootProduct.Products.Count     'count of parts and instances to use
        
    Dim newPart As Product
    Set newPart = rootProduct.Products.AddNewComponent("Part", "Positions") 'create part paste in it
    
    Dim targetPart As Part
    Set targetPart = newPart.ReferenceProduct.Parent.Part

    Dim geomSetTarget As HybridBody
    Set geomSetTarget = targetPart.HybridBodies.Add
    geomSetTarget.Name = "CopyOfReferences"

    Dim vp As VisPropertySet
        
    For i = 1 To PartsCount
        Set instance = rootProduct.Products.Item(i)
        If isVisible(instance) Then                         'hide/show check to copy only visible parts
            
            Dim publCount As Integer
            publCount = rootProduct.Products.Item(i).Publications.Count
            
            Dim selectedEL As Selection
            Set selectedEL = CATIA.ActiveDocument.Selection
            selectedEL.Clear
                                    
            For j = 1 To publCount
                Set publishedEL = rootProduct.Products.Item(i).Publications.Item(j)
                selectedEL.Add publishedEL
                'Debug.Print (rootProduct.Products.Item(i).Publications.Item(j).Name & " published element is added to selection")
                'Debug.Print newPart.Name
                selectedEL.Copy
                selectedEL.Clear
                selectedEL.Add targetPart
                'selectedEL.PasteSpecial ("CATPrtResultWithOutLink")            'paste as result WITHOUT link
                selectedEL.PasteSpecial ("CATPrtResult")                        'paste as result WITH link
                selectedEL.Clear
            Next
        Else
            'Debug.Print (instance.Name & " is NOT visible")
        End If
    Next
    newPart.Update
End Sub

Function isVisible(ByRef object As Variant) As Boolean      'function for cecking hide/show of part
    CATIA.ActiveDocument.Selection.Clear
    CATIA.ActiveDocument.Selection.Add object
    
    Dim vp As VisPropertySet
    Dim showstate As CatVisPropertyStatus
    Set vp = CATIA.ActiveDocument.Selection.VisProperties
    vp.GetShow showstate
    
    result = True
    
    If showstate = catVisPropertyNoShowAttr Then result = False
    
    CATIA.ActiveDocument.Selection.Clear
    
    isVisible = result
End Function 

RE: Copy & Paste published elements in context

thumbsup2

Eric N.
indocti discant et ament meminisse periti

RE: Copy & Paste published elements in context

Now I can share this valuable link.

But I'm glad you stayed here with me and learned & share your result.

Just few more things:

you did comment your code, but not enough... please give more info while commenting. Check CATScript in v5automation.chm

if you want to work with multi level product you need to learn about Recursion.

Eric N.
indocti discant et ament meminisse periti

RE: Copy & Paste published elements in context

(OP)
I'm expanding this macro to retrieve some numbers (position, angle,...) from elements which are copied As result with link, so planes and lines are automatically pasted in External References. Now I'm trying to access them trough HybridBodies, but cant figure out under which collection are they ...

Here is my code:

CODE -->

Sub CATMain()
    Dim rootProduct As Product
    Set rootProduct = CATIA.ActiveDocument.Product
    
    'first check if document is part or product
    If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1 Then
        MsgBox rootProduct.Name & " Is NOT Assembly!"
    Exit Sub
    End If

    Dim PartsCount As Integer
    PartsCount = rootProduct.Products.Count     'count of parts and instances to use
        
    'Enter name od new Part
    Dim newPartName As String
    newPartName = InputBox("Please enter new Part name.")
        
    Dim newPart As Product
    Set newPart = rootProduct.Products.AddNewComponent("Part", newPartName) 'create part paste in it
    
    Dim targetPart As Part
    Set targetPart = newPart.ReferenceProduct.Parent.Part

    'create Geometical set in new part
    'Dim geomSetTarget As HybridBody
    'Set geomSetTarget = targetPart.HybridBodies.Add
    'geomSetTarget.Name = "CopyOfReferences"

    Dim vp As VisPropertySet
        
    'loop trough parts
    For i = 1 To PartsCount
        Set instance = rootProduct.Products.Item(i)
        
        'check if part is visible, so it takes only visible parts
        If isVisible(instance) Then
            
            'count published elements which will be copied
            Dim publCount As Integer
            publCount = rootProduct.Products.Item(i).Publications.Count
            
            Dim selectedEL As Selection
            Set selectedEL = CATIA.ActiveDocument.Selection
            selectedEL.Clear
                                    
            'loop trough published elements in every part
            For j = 1 To publCount
                Set publishedEL = rootProduct.Products.Item(i).Publications.Item(j)
                selectedEL.Add publishedEL
                selectedEL.Copy
                selectedEL.Clear
                selectedEL.Add targetPart
                
                'uncomment if paste WITHOUT link
                'selectedEL.PasteSpecial ("CATPrtResultWithOutLink")
                
                'paste elements WITH link
                selectedEL.PasteSpecial ("CATPrtResult")
                selectedEL.Clear
            Next
        Else
            'Debug.Print (instance.Name & " is NOT visible")
        End If
    Next
    newPart.Update
'--------------------------------------------------------------------------------------
'Section for retreiving positions and rotation angle fo elements

    Dim axisCount As Integer
    Dim LinesCount As Integer
    Dim Xaxis1 As Double
    Dim Xaxis2 As Double
    
    
    LinesCount = targetPart.HybridBodies.HybridBody.Item(1).GeometricElements.Count
    Debug.Print LinesCount
    
    
    'counting axissystems in new part
    axisCount = targetPart.AxisSystems.Count

        'Loop trough axissystems to retreive components
        For i = 1 To axisCount
            Set ASys = targetPart.AxisSystems.Item(i)
            Set Oref = targetPart.CreateReferenceFromObject(ASys)
            Set TheSPAWorkbench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")
            Set TheMeasurable = TheSPAWorkbench.GetMeasurable(Oref)
            
            Dim Components(11)
            TheMeasurable.GetAxisSystem Components
            
            Components(0) = Round(Components(0), 3)
            Components(1) = Round(Components(1), 3)
            Components(2) = Round(Components(2), 3)
            Components(3) = Round(Components(3), 4)
            Components(6) = Round(Components(6), 4)
    
        Debug.Print targetPart.AxisSystems.Item(i).Name & " x "; Components(0) & " y "; Components(1) & " z"; Components(2)
        

        Xaxis1 = Components(3)
        Xaxis2 = Components(6)
        
            If (Xaxis1 = 1) And (Xaxis2 = 0) Then           'Parallel to X
                Debug.Print "Parallel to X"
            ElseIf (Xaxis1 = -1) And (Xaxis2 = 0) Then      'Parallel to X 180° rotated
                Debug.Print "Parallel to X 180° rotated"
            ElseIf (Xaxis1 = 0) And (Xaxis2 = -1) Then      '+90° rotarted
                Debug.Print "+90° rotarted"
            ElseIf (Xaxis1 = 0) And (Xaxis2 = 1) Then       '-90° rotarted
                Debug.Print "-90° rotarted"
            ElseIf (Xaxis1 > 0) And (Xaxis2 < 0) Then       'First quadrant
                Debug.Print "First quadrant"
            ElseIf (Xaxis1 < 0) And (Xaxis2 < 0) Then       'Second quadrant
                Debug.Print "Second quadrant"
            ElseIf (Xaxis1 < 0) And (Xaxis2 > 0) Then       'Third quadrant
                Debug.Print "Third quadrant"
            ElseIf (Xaxis1 > 0) And (Xaxis2 > 0) Then       'Fourth quadrant
                Debug.Print "Fourth quadrant"
            
            End If
        Next

End Sub

Function isVisible(ByRef object As Variant) As Boolean      'function for cecking hide/show of part
    CATIA.ActiveDocument.Selection.Clear
    CATIA.ActiveDocument.Selection.Add object
    
    Dim vp As VisPropertySet
    Dim showstate As CatVisPropertyStatus
    Set vp = CATIA.ActiveDocument.Selection.VisProperties
    vp.GetShow showstate
    
    result = True
    
    If showstate = catVisPropertyNoShowAttr Then result = False
    
    CATIA.ActiveDocument.Selection.Clear
    
    isVisible = result
End Function 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources