Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Hello I am new in Catia macro I a

Status
Not open for further replies.

qayamraza83

Aerospace
Dec 9, 2012
13
DE
Hello
I am new in Catia macro
I am working in a Macro that an hide geometric set and set layer
I have created but it is only working to set Layer

Sub CATMain()

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

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

'---------------------Inform the User when nothing is selected ---------------------'
If objSelection1.Count = 0 Then
MsgBox " Nothing is selected. Please select Multibranchable and Run Macro Again"
Exit Sub
End If
'------------------------------------------------------------------------------------'

'---------------For Changing The Layer---------------'
objSelection1.Search "CATPrtSearch.Rib,sel"
Dim VisProperty1 As VisPropertySet
Set VisProperty1 = objSelection1.VisProperties
Dim LayValue As Long
LayValue = InputBox("Please Enter the Layer Value", "Change of Layer", 180)
VisProperty1.SetLayer catVisLayerBasic, LayValue
'----------------------------------------------------'
objSelection1.Clear

'--------------For Hidding GeometriSet-------------------'
objSelection2.Search "CATPrtSearch.OpenBodyFeature,sel"
Dim Property2 As VisPropertySet
Set Property2 = objSelection2.VisProperties
Property2.SetShow catVisPropertyNoShowAttr
'----------------------------------------------------'
objSelection2.Clear

End Sub
 
Replies continue below

Recommended for you

Hello ferdo
thank u for the reply
yes... you are right
Now i can expect my problem will solve.
There is some bodies other then Part body and some geometric set.
Can you please give me an idea how can we proceed or solve the issue.
 
Thank U ferdo
I will check the doc and try to solve the problem
and post the feedback...................
 
Hello
Friends
This discussion is started some days back.
I am creating a macro to hide geometric set and set layer of Body
with suggestion of some member (especially ferdo), I have created one still I am stuck at one location with error code 424

Sub CATMain()

Dim Document1 As Document
Set Document1 = CATIA.ActiveDocument

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


'---------------------Inform the User when nothing is selected ---------------------'
If objSelection.Count = 0 Then
MsgBox " Nothing is selected. Please select Multibranchable and Run Macro Again"
Exit Sub
End If
'------------------------------------------------------------------------------------'


'--------------For Hidding GeometriSet-------------------'
objSelection.Search "CATPrtSearch.OpenBodyFeature+CATPrtSearch.BodyFeature,sel"
Dim MyArray()
ReDim MyArray(objSelection.Count - 1)
Dim X As Integer
For X = 0 To objSelection.Count - 1
MyArray(X) = objSelection.Item(X + 1).Type
Next

objSelection.Clear

Dim i As Integer
For i = LBound(MyArray) To UBound(MyArray)
If MyArray(i) = "Body" Then
MsgBox MyArray(i)
objSelection.Add MyArray(i) <<<<<<<<<<<<<<<<<<----Error 424 coming on this Line
Dim VisProperty1 As VisPropertySet
Set VisProperty1 = objSelection.VisProperties
VisProperty1.SetLayer catVisLayerBasic, 180
objSelection.Clear
ElseIf MyArray(i) = "HybridBody" Then
MsgBox MyArray(i)
objSelection.Add MyArray(i)
Dim VisProperty2 As VisPropertySet
Set VisProperty2 = objSelection.VisProperties
VisProperty2.SetShow catVisPropertyNoShowAttr
objSelection.Clear
End If
Next i

End Sub
 
Thank u Ferdo for the reply
I will upload our practice model from home.
Till now what I have found is In MsgBox MyArray(i)... it is showing the
stored value in Array (Body and Hybrid Body)
But while adding in ObjSelection.Add it is not considering the "Body" and "Hybrid Body" as object.
But in V5Automation.chm file this are belong to object Type.


 
Hello Ferdo
here is the Product Structure
For macro i have to approach in mind
1. First Select all The BS, FB and SV and then run the macro
on which i stuck

2. Select the top product and Run the macro, Macro will only in BS, FB and SV
and hide the Geometric set and Set the Layer of all bodies.
Which required (i think) more coding then the first one.


 
 http://files.engineering.com/getfile.aspx?folder=044adf0a-9a1a-42df-8a20-399745d8e8be&file=Electric.rar
Lets clarify a little bit for you

1. You want to run first the macro on BS, FB, SV...then, you can notice that names are something like this *-BS* or *-FB* or *-SV* . So, you need to do a search for those elements which has inside those strings...for this you need to read documentation about how to search.

Code for this is
selection2.Search "(Name=*'-'BS* + (Name=*'-'FV* + Name=*'-'SV*)),all"

You can obtain the code by simply recording a CATScript. This will contain a lot of unnecessary lines, including my mistakes in searching syntax [smile].

Code:
Language="VBSCRIPT"

Sub CATMain()

Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument

Dim selection1 As Selection
Set selection1 = productDocument1.Selection

selection1.Search "(Name=*'-'BS* + (Name=*'-'FV* + Name=*'-'SV)),all" ''my mistake in searching syntax

Dim selection2 As Selection
Set selection2 = productDocument1.Selection

selection2.Search "(Name=*'-'BS* + (Name=*'-'FV* + Name=*'-'SV*)),all"

Dim selection3 As Selection
Set selection3 = productDocument1.Selection

selection3.Search "CATPrtSearch.OpenBodyFeature,sel"

Dim selection4 As Selection
Set selection4 = productDocument1.Selection

Dim visPropertySet1 As VisPropertySet
Set visPropertySet1 = selection4.VisProperties

Dim documents1 As Documents
Set documents1 = CATIA.Documents

Dim partDocument1 As Document
Set partDocument1 = documents1.Item("VL39H02340000000-BS001.CATPart")

Dim part1 As Part
Set part1 = partDocument1.Part

Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies

Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Item("Geometrical Set.1")

Set hybridBodies1 = hybridBody1.Parent

Dim bSTR1 As String
bSTR1 = hybridBody1.Name

selection4.Add hybridBody1

Dim hybridBody2 As HybridBody
Set hybridBody2 = hybridBodies1.Item("External References")

Set hybridBodies1 = hybridBody2.Parent

Dim bSTR2 As String
bSTR2 = hybridBody2.Name

selection4.Add hybridBody2

Dim hybridBody3 As HybridBody
Set hybridBody3 = hybridBodies1.Item("Geometrical Set.3")

Set hybridBodies1 = hybridBody3.Parent

Dim bSTR3 As String
bSTR3 = hybridBody3.Name

selection4.Add hybridBody3

Dim partDocument2 As Document
Set partDocument2 = documents1.Item("VL39H02340000000-SV001.CATPart")

Dim part2 As Part
Set part2 = partDocument2.Part

Dim hybridBodies2 As HybridBodies
Set hybridBodies2 = part2.HybridBodies

Dim hybridBody4 As HybridBody
Set hybridBody4 = hybridBodies2.Item("Geometrical Set.1")

Set hybridBodies2 = hybridBody4.Parent

Dim bSTR4 As String
bSTR4 = hybridBody4.Name

selection4.Add hybridBody4

Dim hybridBody5 As HybridBody
Set hybridBody5 = hybridBodies2.Item("External References")

Set hybridBodies2 = hybridBody5.Parent

Dim bSTR5 As String
bSTR5 = hybridBody5.Name

selection4.Add hybridBody5

Dim hybridBody6 As HybridBody
Set hybridBody6 = hybridBodies2.Item("Geometrical Set.3")

Set hybridBodies2 = hybridBody6.Parent

Dim bSTR6 As String
bSTR6 = hybridBody6.Name

selection4.Add hybridBody6

Dim partDocument3 As Document
Set partDocument3 = documents1.Item("VL39C06227000000-BS001.CATPart")

Dim part3 As Part
Set part3 = partDocument3.Part

Dim hybridBodies3 As HybridBodies
Set hybridBodies3 = part3.HybridBodies

Dim hybridBody7 As HybridBody
Set hybridBody7 = hybridBodies3.Item("Geometrical Set.1")

Set hybridBodies3 = hybridBody7.Parent

Dim bSTR7 As String
bSTR7 = hybridBody7.Name

selection4.Add hybridBody7

Dim hybridBody8 As HybridBody
Set hybridBody8 = hybridBodies3.Item("External References")

Set hybridBodies3 = hybridBody8.Parent

Dim bSTR8 As String
bSTR8 = hybridBody8.Name

selection4.Add hybridBody8

Dim hybridBody9 As HybridBody
Set hybridBody9 = hybridBodies3.Item("Geometrical Set.3")

Set hybridBodies3 = hybridBody9.Parent

Dim bSTR9 As String
bSTR9 = hybridBody9.Name

selection4.Add hybridBody9

Set visPropertySet1 = visPropertySet1.Parent

Dim bSTR10 As String
bSTR10 = visPropertySet1.Name

Dim bSTR11 As String
bSTR11 = visPropertySet1.Name

visPropertySet1.SetShow 1

selection4.Clear 

End Sub

Now you need to apply what you learned from v5automation.chm file and clean the code as much as you can.

So, after searching all BS,FV, SV you let them selected and do another search inside that selection. Your target for this search are geometrical sets and this is done like this:
selection3.Search "CATPrtSearch.OpenBodyFeature,sel"

A cleaner code is bellow...try to continue with your step 2 and come back with a nice code

Code:
Language="VBSCRIPT"

Sub CATMain()

Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument

Dim selection2 As Selection
Set selection2 = productDocument1.Selection

selection2.Search "(Name=*'-'BS* + (Name=*'-'FV* + Name=*'-'SV*)),all"

Dim selection3 As Selection
Set selection3 = productDocument1.Selection

selection3.Search "CATPrtSearch.OpenBodyFeature,sel"

Dim visPropertySet1 As VisPropertySet
Set visPropertySet1 = selection3.VisProperties
visPropertySet1.SetShow 1
selection3.Clear 

End Sub



Regards
Fernando

- Romania
- EU
 
Thank u for the code
How can we deal with body to set layer in the same code.
 
Sorry Ferdo
If previously i was not clear.
I want to go with pre selection of Required part.
Then Search body and HybridBody together
and apply layer on body and geometric set hide in one Macro
 
i am confused where i am getting wrong
after first set of work (either it is hidding or setting layer)
code is not working for second given task.
 
Hi Ferdo
Finally i got the solution, with some value input from ferdo
I have change the approach
--> First i have search the -BS, -FS, -SV and -FV
--> Then i have stored this search result in Array
--> one by one this search result in Array is used to achieve the task
----------------
Here is full code
----------------
Option Explicit
Sub CATMain()

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

'---------------------Inform the User when nothing is selected ---------------------
If objSelection.Count = 0 Then
MsgBox " Nothing is selected. Please select Multibranchable and Run Macro Again"
Exit Sub
End If
'------------------------------------------------------------------------------------

objSelection.Search "(Name=*'-'BS* + (Name=*'-'FB* + Name=*'-'SV*+ Name=*'-'FS*)),all"

'--------------------Store the selected Item in Array--------------------------------
Dim TempArray()
ReDim TempArray(objSelection.Count - 1)
Dim X As Integer
For X = 0 To objSelection.Count - 1
Set TempArray(X) = objSelection.Item(X + 1).Value
Next X
'-------------------------------------------------------------------------------------
objSelection.Clear '----Clear the Selection

'------------Calling the stored object in Array---------------------------------------
Dim i As Integer
For i = LBound(TempArray) To UBound(TempArray)
'---------------For Hidding Geometric Set---------------'
Dim objSelection1 As Selection '------ New Selection is created for hidding GeoSet
Set objSelection1 = CATIA.ActiveDocument.Selection
objSelection1.Clear
objSelection1.Add TempArray(i) '-----Add first Array in the selection
objSelection1.Search "CATPrtSearch.OpenBodyFeature,sel" '-----Search for Geo. Set
Dim VisProperty1 As VisPropertySet
Set VisProperty1 = objSelection1.VisProperties
VisProperty1.SetShow catVisPropertyNoShowAttr '-----Hide the GeoSet
objSelection1.Clear '-----Clear the selection
'***************************************************
'---------------For Changing The Layer---------------'
Dim objSelection2 As Selection '------ New Selection is created for hidding GeoSet
Set objSelection2 = CATIA.ActiveDocument.Selection
objSelection2.Clear
objSelection2.Add TempArray(i) '-----Add first Array in the selection
objSelection2.Search "CATPrtSearch.BodyFeature,sel" '-----Search for Body
Dim VisProperty2 As VisPropertySet
Set VisProperty2 = objSelection2.VisProperties
VisProperty2.SetLayer catVisLayerBasic, 180 '-----Search for Body in First stored object
objSelection2.Clear '-----Clear the selection
Next i '-----Going for next stored value
'*****************************************************

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top