Let’s Start Programming! Forums CATIA Macro Programming Delete Geometrical set and Pockets

This topic contains 6 replies, has 3 voices, and was last updated by  Dani 2 years, 2 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #2211

    Dani
    Participant

    Hello everybody,
    I am completely new in catia macros. I have a problem that I think is very simple but i don t know how to fix that. I want to write macro that delete all “Pocket”s and the “Geometrical Set”s from a design tree in catia v5. It seems to me that this is a very simple case but I have no idea how to do that. I would appreciate if you help me.
    Thank you.

    #2212

    Emmett Ross
    Keymaster

    Hi Dani. Glad to see you are trying to get into the world of macros and automation! I highly recommend you join my free email course for a quick introduction to macros here: http://www.scripting4v5.com/newsletter/
    It should be pretty straight forward to find and delete all pocket features. Join the course, give the macro a try, then let us know where you get stuck and we’ll help you out!
    -Emmett

    #2213

    Dani
    Participant

    Thank you Emmett, This is my macro that unfortunately didn’t work.

    Sub CATMain()

    Dim partDocument1 As PartDocument Set partDocument1 = CATIA.ActiveDocument

    Set selection1 = partDocument1.Selection selection1.Search “Name=HybridBody, all” selection1.Delete

    Set selection2 = partDocument1.Selection selection2.Search “Name=Pocket, all” selection2.Delete

    End Sub

    #2260

    Matt
    Participant

    It is very helpful to include any error messages and the line the macro failed on.

    ‘Hopefully you only have a part open or the macro will fail on setting partDocument1
    Dim partDocument1 As PartDocument
    Set partDocument1 = CATIA.ActiveDocument

    ‘You used Name=HybridBody…Name is the actual name of the feature. You want to use Type.
    Set selection1 = partDocument1.Selection
    selection1.Search “Type=HybridBody, all”

    ‘What if there are no geosets in the part? Your Delete method will fail
    If selection1.Count>0 Then
    selection1.Delete
    End if

    You can build the string required by selecting ctrl+f on the keyboard and manually building what you want to search for. Add the search to your favorites and you can copy the string and paste it in your code.

    #2269

    Dani
    Participant

    Thank you Matt,

    But it seems to me that catia does not recognize HydridBody as a form of type.

    When I run this:

    Sub catmain()
    Dim oPartDoc As PartDocument
    Set oPartDoc = catia.ActiveDocument
    Set oSelection1 = oPartDoc.Selection
    oSelection1.Search “type=body, all”
    Dim No As Integer
    No = oSelection1.Count
    MsgBox (No)
    End Sub

    It correctly gives me back the number of bodies in the tree. However when I replace “type=body, all” with “type=hybridbody, all” it brings back this error:
    “The method Search failed”

    Thank you

    #2272

    Matt
    Participant

    I replied to this a week ago but it did not post, sorry 🙁

    Geosets are called “HybridBodies” in VBA but in CATIA they are called Geometrical Sets.

    As i mentioned before:
    You can build the string required by selecting ctrl+f on the keyboard and manually building what you want to search for. Add the search to your favorites and you can copy the string and paste it in your code.

    #2274

    Dani
    Participant

    Thank you Matt

Viewing 7 posts - 1 through 7 (of 7 total)

The forum ‘CATIA Macro Programming’ is closed to new topics and replies.