Forum Replies Created

Viewing 15 posts - 31 through 45 (of 45 total)
  • Author
    Posts
  • in reply to: Activate solid in a part #1328

    Matt
    Participant

    Are you trying to check if you have a product loaded into CATIA?

    in reply to: rename part in product #1315

    Matt
    Participant

    That is fine if the selection is done ahead of time. Did you get the part to go into your collection? Also, you need Namer=Namer+1

    in reply to: Activate solid in a part #1314

    Matt
    Participant

    You’re very welcome. Sometimes in vbScript you have to remove some pare this…not sure why.

    Are you saying you need to check that you have a product loaded? How about

    If UCase(TypeName(CATIA.ActiveDocument)) <> “PRODUCTDOCUMENT) Then
    MsgBox “You must load a product, exiting macro”
    Exit sub
    end If

    in reply to: Activate solid in a part #1285

    Matt
    Participant

    ‘Loop through all parts
    For i = 1 to oPartProducts.Count
    Set oPartProduct = oPartProducts.item(i)

    If oPartProduct.products.count=0 then ‘New line

    Set oPartDocument = oPartProduct.ReferenceProduct.Parent
    Set oPart = oPartDocument.Part
    Set oShape = oPart.FindObjectByName(“Solide.42″)
    ‘Rest of the code
    oPart.Activate(oShape)
    End if
    End if ‘New line

    in reply to: rename part in product #1280

    Matt
    Participant

    Are you in vba or vbscript? Collections only work in vba.

    You have 2 selection objects, you only need 1

    Selectionpart is the selection object, but you did not tell it to select anything, so you can’t put “nothing” into a collection.

    Selection part.count would return 0 because there is nothing selected

    Looping through the parts is EXACTLY like we did it in the last macro. The difference is you are adding the parts to a collection

    ‘Loop through all parts and add to collection
    For i = 1 to oPartProducts.Count
    Collection.add oPartProducts.item(i).ReferenceProduct.Parent.Part
    Next

    in reply to: Activate solid in a part #1279

    Matt
    Participant

    Sorry, I forgot a piece, try this.

    Sub CATMain()

    Dim oRootProductDocument as Document
    Dim oRootProduct As Product
    Dim oPartProducts As Products
    Dim oPartProduct As Product
    Dim oPartDocument As Document
    Dim oPart As Part
    Dim oSelection As Selection
    Dim oBodies as Bodies
    Dim oBody as Body
    Dim oShapes as Shapes
    Dim oShape as Shape

    Dim i As Integer

    Dim bIsInactive As Boolean

    If instr(ucase(CATIA.ActiveDocument.Name), “CATPRODUCT”)<> 0 then

    Set oRootProductDocument = CATIA.ActiveDocument
    Set oRootProduct = oRootProductDocument.Product
    Set oPartProducts = oRootProduct.Products
    Set oSelection = CATIA.ActiveDocument.Selection

    ‘Turn off refresh display
    CATIA.RefreshDisplay = False

    ‘If you are using cache apply design mode to the entire assembly instead of each part
    oRootProduct.ApplyWorkMode DESIGN_MODE

    ‘Loop through all parts
    For i = 1 to oPartProducts.Count
    Set oPartProduct = oPartProducts.item(i)
    Set oPartDocument = oPartProduct.ReferenceProduct.Parent
    Set oPart = oPartDocument.Part
    Set oShape = oPart.FindObjectByName(“Solide.42″)

    If TypeName(oShape) <> “Nothing” Then
    oSelection.Clear
    oSelection.Add oPart
    CATIA.StartWorkbench (“PrtCfg”) ‘starts part design
    oSelection.Clear

    oPart.Activate(oShape)

    End if

    oSelection.Clear
    oSelection.Add oPartProduct
    CATIA.StartWorkbench (“Assembly”) ‘starts assembly design
    oSelection.Clear

    oPart.Update ‘Be careful updating the entire part…if there is something that
    ‘won’t update, the macro will fail. You can update a specific object using
    ‘oPart.UpdateObject oShape
    Next

    ‘Turn on refresh display
    CATIA.RefreshDisplay = True

    Else
    Msgbox “You must have a product loaded”
    End if

    End Sub

    in reply to: Activate solid in a part #1274

    Matt
    Participant

    Great news! To test if you are in a product,

    If instr(ucase(CATIA.ActiveDocument.Name), “CATPRODUCT”) then

    Set oRootProductDocument = CATIA.ActiveDocument
    ‘Rest of code here
    Else
    Msgbox “You must have a product loaded”
    End if

    End sub

    in reply to: Activate solid in a part #1268

    Matt
    Participant

    Paste it into vba and try running it. Vbscript usually skips over lines that fail, instead of giving you an error. VBA will highlight the line that fails. I have never changed the activity of a feature, so the syntax may be wrong. I have also never used IsInactive.

    The issue sounds like it is here:
    bIsInactive = oPart.IsInactive(oShape)
    If bIsInactive = True Then
    oPart.Activate(oShape)

    Keep us posted

    • This reply was modified 3 years, 1 month ago by  Matt. Reason: Typo
    in reply to: Activate solid in a part #1265

    Matt
    Participant

    I don’t speak any other languages, so I am sure your English is better than if I were to try to speak your native language:)

    It is no problem…I had some time and I like helping and learning.

    Now I understand what you are trying to accomplish:) In the attached code I added turning off refreshing the display, checking if the shape is deactivated, and activating it if it is deactivated. Depending on what version of CATIA you are using, you may be able to turn off the Highlight Selected Object using something like CATIA.HSOSynchronized = False…but you have to turn it back on at the end of the macro using something like CATIA.HSOSynchronized = True. But, again, this depends on the version of CATIA. I personally haven’t had any luck doing this.

    So you are aware, VBA, CATScript/catvbs/VBScript are very similar. VBA is more advanced and has more features and functions. It also has intellisense so as you type your code it pops up available options…like when you text message on a phone and it tries to decide what you are typing. It is very helpful for those who are just starting to write code. For example, as you were typing the line oPart.Activate.oShape, after you typed oPart.Activate. intellisense would either popup all the available options for this method OR nothing would popup telling you that you were doing something incorrectly. So you would try oPart.Activate and put a space…still nothing would popup. Then you try oPart.Acitvate( and suddenly intellisense would popup some options or a string that tells you the type of argument you need. You can also stop your macro where ever you want and use the locals window to debug issues. You can highlight a word and hit F1 key to go to VBA help or if it is a CATIA specific function it will take you into the CATIA Automation chm file where you can browse everything to do with CATIA VB. Things aren’t always clear, but it can be very helpful.

    CATScript/catvbs/VBScript are not as advanced and do not contain the same functionalities as VBA. For example, in VBA you can add a collection of all your shapes so you can loop through them over and over to gather different properties.
    CATScript/catvbs/VBScript doesn’t have a collections class so you have to use arrays which is more difficult (in my opinion). They also do not give you intellisense so it makes it very difficult. Do debug in CATScript/catvbs/VBScript you really can only use message boxes to check your code.

    You get to VBA by pressing alt+F11 in catia. It will look difficult but is very helpful.

    One other thing I like to do is map out exactly what I need my macro to do, then “eat the elephant one bite at a time”. Start small, go step by step writing your code. Once you get a step to work, move on to the next. When you have something that works, go back and organize it/clean it up.

    Anyway, here is the code. Let us know how it works.

    Sub CATMain()

    Dim oRootProductDocument as Document
    Dim oRootProduct As Product
    Dim oPartProducts As Products
    Dim oPartProduct As Product
    Dim oPartDocument As Document
    Dim oPart As Part
    Dim oSelection As Selection
    Dim oBodies as Bodies
    Dim oBody as Body
    Dim oShapes as Shapes
    Dim oShape as Shape

    Dim i As Integer

    Dim bIsInactive As Boolean

    Set oRootProductDocument = CATIA.ActiveDocument
    Set oRootProduct = oRootProductDocument.Product
    Set oPartProducts = oRootProduct.Products
    Set oSelection = CATIA.ActiveDocument.Selection

    ‘Turn off refresh display
    CATIA.RefreshDisplay = False

    ‘If you are using cache apply design mode to the entire assembly instead of each part
    oRootProduct.ApplyWorkMode DESIGN_MODE

    ‘Loop through all parts
    For i = 1 to oPartProducts.Count
    Set oPartProduct = oPartProducts.item(i)
    Set oPartDocument = oPartProduct.ReferenceProduct.Parent
    Set oPart = oPartDocument.Part
    Set oShape = oPart.FindObjectByName(“Solide.42”)

    If TypeName(oShape) <> “Nothing” Then
    oSelection.Clear
    oSelection.Add oPart
    CATIA.StartWorkbench (“PrtCfg”) ‘starts part design
    oSelection.Clear

    bIsInactive = oPart.IsInactive(oShape)
    If bIsInactive = True Then
    oPart.Activate(oShape)
    End if

    End if

    oSelection.Clear
    oSelection.Add oPartProduct
    CATIA.StartWorkbench (“Assembly”) ‘starts assembly design
    oSelection.Clear

    oPart.Update ‘Be careful updating the entire part…if there is something that
    ‘won’t update, the macro will fail. You can update a specific object using
    ‘oPart.UpdateObject oShape
    Next

    ‘Turn on refresh display
    CATIA.RefreshDisplay = True

    End Sub

    in reply to: Activate solid in a part #1254

    Matt
    Participant

    Ramzar,
    I am not sure of everything you want to do with this code, but it seemed like there were some lines that were not needed. Please see the code below. I rewrote it and changed the variable names to reduce confusion for me. If you can post if you are using VBA or CATScript/VBScript, that is very important. One other thing to note, it appears this blog changes quotation and apostrophe characters when you copy/paste code…this could also contribute to your issues.

    Sub CATMain()

    Dim oRootProductDocument as Document
    Dim oRootProduct As Product
    Dim oPartProducts As Products
    Dim oPartProduct As Product
    Dim oPartDocument As Document
    Dim oPart As Part
    Dim oSelection As Selection

    Dim oShape as Shape

    Dim i As Integer

    Set oRootProductDocument = CATIA.ActiveDocument
    Set oRootProduct = oRootProductDocument.Product
    Set oPartProducts = oRootProduct.Products
    Set oSelection = CATIA.ActiveDocument.Selection

    ‘If you are using cache apply design mode to the entire assembly instead of each part
    oRootProduct.ApplyWorkMode DESIGN_MODE

    ‘Lets wait to check if features are deactivated

    ‘Loop through all parts
    For i = 1 to oPartProducts.Count
    Set oPartProduct = oPartProducts.item(i)
    Set oPartDocument = oPartProduct.ReferenceProduct.Parent
    Set oPart = oPartDocument.Part
    Set oShape = oPart.FindObjectByName(“Solide.42”)

    If TypeName(oShape) <> “Nothing” Then
    oSelection.Clear
    oSelection.Add oPart
    CATIA.StartWorkbench (“PrtCfg”) ‘starts part design
    oSelection.Clear

    oPart.InWorkObject = oShape
    ‘Do something to oShape
    End if

    oSelection.Clear
    oSelection.Add oPartProduct
    CATIA.StartWorkbench (“Assembly”) ‘starts assembly design
    oSelection.Clear

    oPart.Update ‘Be careful updating the entire part…if there is something that
    ‘won’t update, the macro will fail. You can update a specific object using
    ‘oPart.UpdateObject oShape
    Next

    End Sub

    in reply to: Activate solid in a part #1253

    Matt
    Participant

    looking at the code again, I think there is another problem at the start:

    This searches for all bodies named “conv” and adds them to the selection
    Set selection = CATIA.ActiveDocument.Selection
    selection.Search “CATPrtSearch.BodyFeature.NameInGraph=conv,all”

    This second selection variable is really the same as the first selection variable. It looks like this one is searching everything you had selected from the previous search and is looking for features that are deactivated and it will select those deactivated features.
    Dim selection1 As Selection
    Set selection1 = CATIA.ActiveDocument.Selection
    selection1.Search “CATPrtSearch.MechanicalFeature.Activity=FALSE,sel”

    The problem is, when the second search finds that no features are deactivated…it has 0 objects in the selection! So when you get to your if statement…

    If selection1.Count = 0 Then
    Msgbox “No desactivated features.”
    Else

    Does the Msgbox “No desactivated features.” get shown on your screen?

    If it does that means there is nothing in the selection…so your next If statement will surely not work because there are 0 objects in the selection.

    If selection1.Count > 0 Then

    I’ll look at the code.

    in reply to: Activate solid in a part #1252

    Matt
    Participant

    Can you post the errors and the lines they occur at? Do you message boxes earlier in the code work properly? Also, are you writing in VBA or VBScript/CATScript?

    in reply to: Activate solid in a part #1249

    Matt
    Participant

    Np, Emmett. Lots of people have helped me (and still do)…glad I can start giving back a little. I am glad you finally opened the forum to everyone.

    in reply to: Activate solid in a part #1238

    Matt
    Participant

    I just noticed you set partDocument1 = a product. You are looping part products but setting the documents…why not set the part products then set the document and then the part?

    Dim partProduct1 as Product ‘add this variable

    For I = 1 to product1.Products.Count
    Set partProduct1 = products1.item(I)
    Set partDocument1 = partProduct1.ReferenceProduct.Parent
    Set part1 = partDocument1.Part
    ‘Continue with your code

    Also I would Dim outside of the For loop…no need to keep dimming over and over

    Sorry, did not see your other question…No applying design mode switches the part from a CGR (basically a 3D picture created in cache mode) to exposing the history and publications so you can work on it (or something like that:).

    If you want to activate the part design workbench you can add the part to the selection then change the workbench:
    CATIA.ActiveDocument.Selection.Clear
    CATIA.ActiveDocument.Selection.Add part1
    CATIA.StartWorkbench (“PrtCfg”)’starts part design
    CATIA.ActiveDocument.Selection.Clear
    ‘Activate your solid

    Before you can put the next part in the part design work bench, you need to switch back to assembly design or an empty part will open
    CATIA.ActiveDocument.Selection.Clear
    CATIA.ActiveDocument.Selection.Add partProduct1
    CATIA.StartWorkbench (“Assembly”)’starts assembly design
    CATIA.ActiveDocument.Selection.Clear

    • This reply was modified 3 years, 1 month ago by  Matt.
    • This reply was modified 3 years, 1 month ago by  Matt.
    • This reply was modified 3 years, 1 month ago by  Matt. Reason: Typos etc
    in reply to: Activate solid in a part #1233

    Matt
    Participant

    You dim part1 as a part, but you set it equal to a document. I believe the line is failing because there is no Bodies collection in a document. Try Set part1 = partDocument1.part

Viewing 15 posts - 31 through 45 (of 45 total)