Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Catvba Updated constraints

Status
Not open for further replies.

TudorM

Automotive
Mar 30, 2020
99
0
6
AT
Hello guys , i am trying to retrieve the updated constraints from a product and delete them , but no succes.
I am new to VBA so please understand.

I have the following script :


Sub CATMain()


Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument

Dim product1 As Product
Set product1 = productDocument1.Product

Dim constraints1 As Constraints
Set constraints1 = product1.Connections("CATIAConstraints")

Dim CstUpd As Long
CstUpd = constraints1.UnUpdatedConstraintsCount

CstUpd.Remove


End Sub


Please help ,thank you.
 
Replies continue below

Recommended for you

-Trying to understand the language , my first idea was to delete the broken ones and i saw that it is only a property name in difference so i just posted updated ones.
 
I really tried but still do not know how to join everything...? :(

Sub CATMain()

Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument

Dim product1 As Product
Set product1 = productDocument1.Product

Dim constraints1 As Constraints
Set constraints1 = product1.Connections("CATIAConstraints")

Dim i As Integer
For i = 1 To my_constraints.Count '-- ok now i have collection of constraints next i need some of them with specific properties : (UnUpdatedConstraintsCount) to delete what do i say next please help?



Next
End sub







 
Check always the documentation and see the status of your constraints. See also DS examples in that file.

image_amciz0.png


Regards
Fernando

 
Thank you Fernando for your help , it has something to do with this :
image_f4wwzj.png

and catCstStatusKOBroken , now i am really confused or maybe it's late...

So what i am trying to do is to delete this constraint wich requires update, maybe i didn't explained well....
Untitled_ggiw5m.jpg
 
This morning i tried this :

Sub CATMain()


Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument

Dim product1 As Product
Set product1 = productDocument1.Product

Dim constraints1 As Constraints
Set constraints1 = product1.Connections("CATIAConstraints")

Dim i As Integer
For i = 1 To constraints1.Count
If (constraints1.Item(i).Status = catCstStatusKOBroken) Then

constraints1.Remove (constraints1.UnUpdatedConstraintsCount)

End If

Next

End Sub


But nothing happens...
 
Those are different thinks, your image clarifies a little bit more what you want to do.
Just for my curiosity, why you want to delete? Shouldn't be first force update and then delete if it is not OK?

You have to check the status, add to a collection and delete, maybe something like this (I didn't try in CATIA, but maybe you can upload here a sample)

For Each oConst In oConsts
If oConst.Status = UnUpdatedConstraintsCount Then
oSel.Add oConst
End If
Next





Regards
Fernando

 
Hello Ferdo thank you for you response and i am sorry if didn't post right from the beginning, i will try to explain my thoughts :
For example i have done a welded structure like this
Capture_fbzfwv.jpg

and it has a lot of constraints from the begining of the concept (when i started ) after a client review he wants me to do modify some lenghts for examaple and if i am moving elements they are asking for update and if they are like 100 its easier to delete and fix ( if you know what you doing ) . Also i saw that the call for UnUpdatedConstraintsCount property is same as BROKEN ones so i said to do one vba for UNupdated and next one for Broken should be similar.

I will try to implement what you sent, and if i succeed will post here thank you very much.
 
Hello, i still didn't find a solution tho i am thinking i am close to it :( , please someone have a look,thank you !!!



Sub CATMain()


Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument

Dim product1 As Product
Set product1 = productDocument1.Product

Dim my_constraints As Constraints
Set my_constraints = product1.Connections("CATIAConstraints")


Dim osel As Selection
Set osel = CATIA.ActiveDocument.Selection
Dim i As Integer
For i = 1 To my_constraints.Count

Dim MyCons As Constraint
Set MyCons = my_constraints.Item(i)

Dim iConstraintStatus As CatConstraintStatus
Set iConstraintStatus = MyCons.Status

If iConstraintStatus = catCstStatusKOBroken Then

osel.Add (MyCons)
osel.Remove (MyCons)



End If
Next

End Sub
 
Code:
Sub CATMain()

Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument

Dim product1 As Product
Set product1 = productDocument1.Product

Dim my_constraints As Constraints
Set my_constraints = product1.Connections("CATIAConstraints")

Dim osel As Selection
Set osel = CATIA.ActiveDocument.Selection

Dim i As Integer
For i = 1 To my_constraints.Count
    Dim MyCons As Constraint
    Set MyCons = my_constraints.Item(i)

    Dim iConstraintStatus As CatConstraintStatus
    'Set iConstraintStatus = MyCons.Status
    
    If iConstraintStatus = catCstStatusKOBroken Then
        osel.Add (MyCons)
    End If
Next

osel.Delete

End Sub
 
Thank you for your time but not working
Capture_bslzlj.jpg

and i have a feeling that it must contain smth. with

o Property BrokenConstraintsCount( ) As long (Read Only)

Returns the number of broken constraints from the Constraints collection.
Example:
The following example retrieves in BknCstNum the number of broken constraints from the myListofConstraints collection of constraints:
BknCstNum = myListofConstraints.BrokenConstraintsCount

o Property UnUpdatedConstraintsCount( ) As long (Read Only)

Returns the number of unupdated constraints from the Constraints collection.
Example:
The following example retrieves in UnUpdCstNum the number of unupdated constraints from the myListofConstraints collection of constraints:
UnUpdCstNum = myListofConstraints.UnUpdatedConstraintsCount


Cause i want to do one for UnUpdatedConstraintsCount and one for BrokenConstraintsCount (also i think catCstStatusKOBroken
The constraint is not satisfied because a geometric element is missing. It can happen in an assembly when a part is missing.
) has to do only for broken ones.

Sorry , i am new to catvba , but i really tried and cannot find solution this is last version how i am thinking it should be please have a look :
fasfsfsdf_ylx0g7.jpg
 
Please try with below code
Code:
Sub CATMain()

Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument

Dim product1 As Product
Set product1 = productDocument1.Product

Dim my_constraints As Constraints
Set my_constraints = product1.Connections("CATIAConstraints")

Dim osel As Selection
Set osel = CATIA.ActiveDocument.Selection

Dim i As Integer
For i = 1 To my_constraints.Count
    Dim MyCons As Constraint
    Set MyCons = my_constraints.Item(i)

    Dim iConstraintStatus As CatConstraintStatus
    iConstraintStatus = MyCons.Status 'iConstraintStatus is an enum doesn't need 'set' keyword
    
    If iConstraintStatus = catCstStatusKOBroken Then
        osel.Add MyCons
    End If
Next

osel.Delete

End Sub
 
Thank you guys , you are the best , helped me a lot ,works very good for broken ones last request how it should be for UnUpdated ones ??


 
Ok finally i got it : for Unupdated needed this : {If iConstraintStatus = catCstStatusKOStronglyNotSatisfied Then}

A huge THANK YOU to all of you !!!

 
Status
Not open for further replies.
Back
Top