Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

I forget holes everytime so I want to make a macro 3

Status
Not open for further replies.

Dialga1

Mechanical
Jan 1, 2023
15
0
0
TR
Hello friends I'm new in Catia macro. I have several questions.

1) I tried to save macro but it didn't worked in opacity and colour. I want to make 0% or 25% opacity all of the product and giving white colour.

2) In product I need to find all holes. Give all holes red color and count them (I found counting code).

3) Can I confirm another colour for other type holes? For example simple hole is yellow and counterbored is red.

I added a picture for my example without code :)
 
 https://files.engineering.com/getfile.aspx?folder=ba385c8b-48a9-4c5e-b3ae-5b450e34b3e1&file=Snipaste_2023-01-01_20-33-15.png
Replies continue below

Recommended for you

Thank you LWolf I used this code for first option how can I adapt search code to macro? For example make this searched holes green.

Language="VBSCRIPT"

Sub CATMain()

Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument

Dim selection1 As Selection
Set selection1 = productDocument1.Selection

Set visPropertySet1 = selection1.VisProperties
visPropertySet1.SetRealColor 210,210,255,1

Set visProperties1 = CATIA.ActiveDocument.Selection.VisProperties
visProperties1.SetRealOpacity 128,1

selection1.Clear

End Sub
 
I tried but It gives me errors Mr Ferdo can you check my code? I'm not sure my code is search holes. My first code works well makes opacity and gives colours to product.

Language="VBSCRIPT"

Sub CATMain()

Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument

Dim selection1 As Selection
Set selection1 = productDocument1.Selection

Set visPropertySet1 = selection1.VisProperties
visPropertySet1.SetRealColor 210,210,255,1

Set visProperties1 = CATIA.ActiveDocument.Selection.VisProperties
visProperties1.SetRealOpacity 128,1

Selection1.Clear

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

objSel.Search("Hole=Simple;all")

Set visPropertySet1 = selection1.VisProperties
visPropertySet1.SetRealColor 255,255,0

Set visProperties1 = CATIA.ActiveDocument.Selection.VisProperties
visProperties1.SetRealOpacity 255,1

Selection1.Clear

Set objSel =CATIA.ActiveDocument.Selection

objSel.Search(“Hole=Counterbored;all”)

Set visPropertySet1 = selection1.VisProperties
visPropertySet1.SetRealColor 0,0,255

Set visProperties1 = CATIA.ActiveDocument.Selection.VisProperties
visProperties1.SetRealOpacity 255,1

Selection1.Clear

End Sub
 
This is a macro recorded in 3DXEXPERIENCE, you need to adapt for v5, so, for example, instead of ActiveEditor write ActiveDocument...I don't have any v5 for the time being ...is coloring only Counterbored.

Code:
Language="VBSCRIPT"

Sub CATMain()


Dim editor1 As Editor
Set editor1 = CATIA.ActiveEditor

Dim selection1 As Selection
Set selection1 = editor1.Selection

selection1.Search "CATPrtSearch.Hole.HoleType=Counterbored,all"

		Set visPropertySet1 = selection1.VisProperties 
		visPropertySet1.SetRealColor 255,255,0,0

End Sub

Regards
Fernando

 
Hi again Mr. Ferdo. Sorry about my bad english also I adding a picture I tried my best.



It works very good thank you now but I stuck in something in code I entered 100% opacity for holes but they are still are transparent. In product how can I turn my holes full opacity and all of other elements products %0 opacity and colourless. Now in code everything is 0 opacity but reads colours :) also when I click in main product automatic graphic proporties It show colours If I not click to this button not showing the colours

Code:
Language="VBSCRIPT"

Sub CATMain()

Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument

Dim selection1 As Selection
Set selection1 = productDocument1.Selection

Set visPropertySet1 = selection1.VisProperties
visPropertySet1.SetRealColor 210,210,255,1

Set visProperties1 = CATIA.ActiveDocument.Selection.VisProperties
visProperties1.SetRealOpacity 128,1






selection1.Search "CATPrtSearch.Hole.HoleType=Simple,all"

Set visPropertySet1 = selection1.VisProperties
visPropertySet1.SetRealColor 255,255,0,0

Set visProperties1 = CATIA.ActiveDocument.Selection.VisProperties
visProperties1.SetRealOpacity 255,1




selection1.Search "CATPrtSearch.Hole.HoleType=Counterbored,all"

Set visPropertySet1 = selection1.VisProperties
visPropertySet1.SetRealColor 0,0,255,0

Set visProperties1 = CATIA.ActiveDocument.Selection.VisProperties
visProperties1.SetRealOpacity 255,1




End Sub

Sincerely
Mert.
 
 https://files.engineering.com/getfile.aspx?folder=d390d481-bf83-44af-8416-79d96cf631b5&file=Snipaste_2023-01-07_16-51-31.png
Code:
Sub CATMain()

Dim editor1 As Editor
Set editor1 = CATIA.ActiveEditor

Dim selection1 As Selection
Set selection1 = editor1.Selection

selection1.Search "Name=*PartBody*,all"

Set visPropertySet1 = selection1.VisProperties
visPropertySet1.SetRealColor 210,210,255,1

Set visProperties1 = CATIA.ActiveEditor.Selection.VisProperties
visProperties1.SetRealOpacity 128,0

selection1.Search "CATPrtSearch.Hole.HoleType=Counterbored,all"

		Set visPropertySet1 = selection1.VisProperties 
		visPropertySet1.SetRealColor 255,255,0,0
         visProperties1.SetRealOpacity 255,1

selection1.Search "CATPrtSearch.Hole.HoleType=Simple,all"

		Set visPropertySet1 = selection1.VisProperties 
		visPropertySet1.SetRealColor 255,155,0,0
         visProperties1.SetRealOpacity 255,1

End Sub

Regards
Fernando

 
Status
Not open for further replies.
Back
Top