Let’s Start Programming! Forums CATIA Macro Programming Intersection and add(boolean)

This topic contains 5 replies, has 2 voices, and was last updated by  Matt 2 years, 10 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1424

    ramzar
    Participant

    Hi all, i need help for a part of my macro. It’s been 3 weeks now i’m trying to do it. My macro is quite long but here is a resume of it.

    I have, in my root assembly, multiple parts. At the bottom, i have a sub-assembly with part in it(screws). I want, in each of my part, do a intersection with the screw and the part, if there is, do a Add boolean (put the boolean under “split”), if no intersection, try next screw.

    Here is my code, i’ll try to put as much info as i can so the macro will be clear.

    You can look a pictures in attachment for a better comprehension. In attachment 1, you can see my tree with the sub-assembly “VIS” at the bottom. Attachment 2 is in the sub-assembly, how the screw(part) is made. I want to to an itersect with “remove hole” who is put in the collection.Attachment 3 is in the part, i want to put the boolean add after “split”.

    If not clear, feel free to ask!

    Thank you!!!

    Sub CATMain()

    Dim productDocument1 As Document
    Dim product1 As Product
    Dim products1 As Products
    Dim partproducttest As Product

    Dim visproductDocument1 As Document
    Dim visproduct1 As Product
    Dim visproducts1 As Products
    Dim vispartdoc As partdocument
    Dim vispartdocument As Document
    Dim vispart As part
    Dim vispartproduct As Product
    Dim viscollection As New collection
    Dim removehole As Body
    Dim selection As selection

    Dim partremoveprod As Product
    Dim partremovedocument As Document
    Dim partremove As part
    Dim partsplitremove As Body
    Dim visremove As Body

    Dim woid As String ‘workobjectid to verify if i’m in a product or part

    Set productDocument1 = CATIA.ActiveDocument
    Set product1 = productDocument1.Product
    Set products1 = product1.Products
    Set selection = CATIA.ActiveDocument.selection

    woid = CATIA.GetWorkbenchId

    If woid <> “Assembly” Then ‘verification if i’m in product or part
    MsgBox (“Mettre actif sur le product”)
    End
    End If

    ‘Number of part in product
    partcount = products1.Count

    ‘Fin an other product in tree (where the screws are)
    Dim a As Integer
    For a = 1 To partcount
    Set partproducttest = products1.Item(a)

    ‘Verify if there is parts inside the sub-assembly
    If partproducttest.Products.Count > 0 Then ‘ If #1

    Set visproduct1 = products1.Item(a).Products
    Set visproducts1 = visproduct1.Products

    ‘Number of screws in the sub-assembly “vis”
    partcountvis = visproducts1.Count

    ‘Beginning of loop to put “remove hole” in a collection
    Dim b As Integer
    For b = 1 To partcountvis
    Set visproduct1 = visproducts1.Item(b)
    Set vispartdocument = visproduct1.ReferenceProduct.Parent
    Set vispart = vispartdocument.part

    Set removehole = vispart.FindObjectByName(“Remove Hole”)

    If TypeName(removehole) <> “Nothing” Then ‘If #2
    viscollection.Add removehole
    End If ‘If #2

    Next ‘b

    ‘Look into each part to find if there is a “split” if not go next, if yes go in
    Dim c As Integer
    For c = 1 To partcount

    Set partremoveprod = products1.Item(c)
    Set partremovedocument = partremoveprod.ReferenceProduct.Parent
    Set partremove = partremovedocument.part
    Set partsplitremove = partremove.FindObjectByName(“split”)

    If TypeName(partsplitremove) <> “Nothing” Then ‘If #3

    ‘Go in the part and change workbench
    selection.Clear
    selection.Add partremove
    CATIA.StartWorkbench (“PrtCfg”)
    selection.Clear

    ‘Put the Inworkobject on split so the boolean operation will go under
    partremove.InWorkObject = partsplitremove

    ‘pick up screw in the collection
    Dim d As Integer
    For d = 1 To partcountvis
    Set visremove = viscollection.Item(d)

    HERE IS THE PLACE FOR THE INTERSECTION AND BOOLEAN ADD

    ‘Go out of the part and go on next one
    selection.Clear
    selection.Add partremoveprod
    CATIA.StartWorkbench (“Assembly”)
    selection.Clear

    Next ‘d

    End If ‘If #3
    Next ‘c

    End If ‘If #1

    Next ‘a
    End Sub

    #1431

    Matt
    Participant

    I’m sorry, I’m a little confused. Are you intersecting the bolt to the part? Could you do something that does not require the creation of geometry…like measure from the bolt centerline to the center point of the attachment hole?

    If the distance is 0mm you would need to copy the body for that bolt and paste it into the part.

    #1434

    ramzar
    Participant

    Hi matt, yes, at first, i want to do an intersection but i don’t want to create the fonction in the part. If the screw intersect the part, then i want to create a Add in the part (under “split”). I dont think the mesurment would work. I prefer doing an intersect to verify if the bolt is really in the piece or not.

    And about copying the screw in the part before doing an Add, i can try that but for now i dont even know how to just to an intersect without creating the fonction in the part and how to do the Add and create the fonction by the same occasion.

    • This reply was modified 2 years, 11 months ago by  ramzar.
    #1437

    Matt
    Participant

    So you are intersecting a part with a bolt…the part does not have a hole for the bolt to pass through?

    You cannot create geometry outside of a part. So if you want to make an intersect between the bolt and the part, both of the features (the bolt and the part) need to exist in the same part and an intersect needs to be created.

    If there is no hole where the bolt will pass through, take a measurement between the bolt and the part. If the distance = 0, you know they intersect.

    #1438

    ramzar
    Participant

    Hi Matt, yes i’m intersection a bolt with a part. The part dont have any holes in it. If you look at the picture, my bolt are a part in an assembly, and in each part, there is “removehole”. This is a body i want to remove in my part under “split”. I dont want to create a function under split with removehole, only do a verification if they intersect. If yes, then i want to create the fonction “add” with “removehole” under “split”. Your idea of copying before is good. I’ll try to do that. I dont know if i can do that from a collection but i’ll try. The idea of measurement is good, i’ll try to do the intersect first and if its not working, then i’ll try it. Thanks, and have a happy christmas!!

    #1446

    Matt
    Participant

    It will be easier to measure because you will not need to paste the bolts into the part to create the intersect. Use the SPA workbench to make measurements.

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

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