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!

Search strings in macro

Status
Not open for further replies.

Alan Lowbands

Aerospace
May 17, 2017
274
GB
Hi
Does anyone know where I can find a list of the search strings for catia scripts

eg selection1.Search "Type=Hole,all"
I have looked in V5 automation but couldn't find anything, probably don't know where to look
what other options do you have?

thanks for any pointers
Alan
 
Replies continue below

Recommended for you

Best way to do this in my experience is to manually create the search in the 'Find' command under the Advanced tab, save the Search as a Favorite Search, then edit the Favorite search to obtain the search you created manually.
 
Hi Thanks for the reply,
I managed to find the search I needed
selection1.Search "Type=Hole,sel" ( I only wanted the macro to run on the selected items note all of them)
This seems to have cured it.

Now I'm stuck on altering the perameters of c/sunk holes

oHole1.ThreadingMode = catSmoothHoleThreading
oHole1.BottomLimit.LimitMode = catUpThruNextLimit
oHole1.Diameter.Value = holeDia

oHole1.Type = catSimpleHole
'Case "Counterbored"
'oHole1.Type = catCounterboredHole
'oHole1.HeadDiameter.Value = holeCDia This bit runs fine when active
'oHole1.HeadDepth.Value = holeCDpt


oHole1.Type = catCSModeDepthAngle
oHole1.HeadAngle.Value = 90.0000 This bit won't :(
oHole1.HeadDepth.Value = 5.0

Anyone know where I'm going wrong ?

cheers
Alan
 
check the CAA V5 Visual Basic help:
o Property CounterSunkMode( ) As CatCSHoleMode

Returns the mode of a countersunk hole .
Returns:
CSMode Value of the countersunk mode (see CatCSHoleMode for list of possible types)
Example:
The following example returns in CSMode the CSMode of hole firsthole:
Set CSMode = firsthole.CounterSunkMode

o Property Diameter( ) As Length (Read Only)

Returns the hole diameter.
Returns:
oDiameter A Length object controlling the hole diameter (see Length for more information)
Example:
The following example returns in holeDiam the diameter of hole firstHole:
Set holeDiam = firstHole.Diameter

o Property HeadAngle( ) As Angle (Read Only)

Returns the hole head angle.
This call is valid when the hole type is : Tapered or Counterdrilled or Countersunk.

Returns:
oHeadAngle An Angle object controlling the hole head angle (see Angle for more information)
Example:
The following example returns in holeHeadAngle the head angle of hole firstHole:
Set holeHeadAngle = firstHole.HeadAngle

o Property HeadDepth( ) As Length (Read Only)

Returns the hole head depth.
This call is valid when the hole type is : Counterbored or Counterdrilled or Countersunk.

Returns:
oHeadDepth A Length object controlling the hole head depth (see Length for more information)
Example:
The following example returns in holeHeadDepth the head depth of hole firstHole:
Set holeHeadDepth = firstHole.HeadDepth

o Property HeadDiameter( ) As Length (Read Only)

Returns the hole head diameter.
This call is valid when the hole type is : Counterbored or Counterdrilled.

Returns:
oHeadDiameter A Length object controlling the hole head diameter (see Length for more information)
Example:
The following example returns in holeHeadDiam the head diameter of hole firstHole:
Set holeHeadDiam = firstHole.HeadDiameter

o Property HoleThreadDescription( ) As StrParam (Read Only)

Returns the hole thread description parameter. This call is valid when the hole threading mode is : CATThreadedHoleThreading.
This call is valid only when a standard/user design table exists
Returns:
oThreadDescParam A Parameter object controlling the hole thread description (see StrParam for more information)
Example:
The following example returns in holeThreadDescription the thread description (M12 etc) of hole firstHole:
Set holeThreadDescription = firstHole.HoleThreadDescription

o Property ThreadDepth( ) As Length (Read Only)

Returns the hole thread depth.
This call is valid when the hole threading mode is : CATThreadedHoleThreading.

Returns:
oThreadDepth A Length object controlling the hole thread depth (see Length for more information)
Example:
The following example returns in holeThreadDepth the thread depth of hole firstHole:
Set holeThreadDepth = firstHole.ThreadDepth



regards,
LWolf
 
thanks LWolf
I'll have a go and see if I can get my head around it :)

regards
Alan
 
Alan, try to record the hole creation... it gives you all the right syntax.

Dim hole1 As Hole
Set hole1 = shapeFactory1.AddNewHoleWith2Constraints(346.089813, 277.979401, 20#, reference1, reference2, reference3, 10#)

hole1.Type = catCounterboredHole
hole1.AnchorMode = catExtremPointHoleAnchor
hole1.BottomType = catVHoleBottom

Dim limit1 As Limit
Set limit1 = hole1.BottomLimit
limit1.LimitMode = catOffsetLimit

Dim length1 As Length
Set length1 = hole1.Diameter
length1.Value = 10#

Dim angle1 As Angle
Set angle1 = hole1.BottomAngle
angle1.Value = 130#

Dim parameters1 As Parameters
Set parameters1 = part1.Parameters
Dim length2 As Length
Set length2 = parameters1.item("DR_START_PART_COMMON_1\PartBody\Hole.3\HoleCounterBoredType.3\Diameter")

length2.Value = 15#
Dim parameters2 As Parameters
Set parameters2 = part1.Parameters

Dim length3 As Length
Set length3 = parameters2.item("DR_START_PART_COMMON_1\PartBody\Hole.3\HoleCounterBoredType.3\Depth")
length3.Value = 5#

hole1.ThreadingMode = catSmoothHoleThreading

Dim sketch1 As Sketch
Set sketch1 = hole1.Sketch

Dim constraints1 As Constraints
Set constraints1 = sketch1.Constraints

Dim constraint1 As Constraint
Set constraint1 = constraints1.item("Offset.9")

Dim length4 As Length
Set length4 = constraint1.Dimension
length4.Value = 91.866516

Dim constraint2 As Constraint
Set constraint2 = constraints1.item("Offset.10")

Dim length5 As Length
Set length5 = constraint2.Dimension
length5.Value = 164.725525

hole1.ThreadSide = catRightThreadSide
hole1.Type = catCountersunkHole
hole1.CounterSunkMode = catCSModeDepthAngle

Dim parameters3 As Parameters
Set parameters3 = part1.Parameters

Dim length6 As Length
Set length6 = parameters3.item("DR_START_PART_COMMON_1\PartBody\Hole.3\HoleCounterSunkType.1\Depth")
length6.Value = 5#

Dim parameters4 As Parameters
Set parameters4 = part1.Parameters

Dim angle2 As Angle
Set angle2 = parameters4.item("DR_START_PART_COMMON_1\PartBody\Hole.3\HoleCounterSunkType.1\Angle")
angle2.Value = 90#

regards,
LWolf
 
Thanks again LWolf,
I am trying to learn to do this properly and bought the Scripting for V5 from Emmett Ross last year.
I am finding it hard work but it is helping.
Main trouble I have is I usually need a macro right in the middle of a job and so can't spend ages working on it so end up botching things just to get a result.
The one I needed help on was to simply change the c/sunk heads and hole diameters from imperial sized holes to the nearest metric equivalent.
Anyway I botched this up and it works (Kind of) and saves me constantly looking at hole charts.

thanks for your help
Alan

----------------------------------------------------------------------------------------

Sub CATMain()

Dim oManuName
oManuName=InputBox ( "Enter Screw size M?" )

Dim holeDia
Dim holeHDAngle
Dim holeHDDepth
Dim holeName
If oManuName = 3 then holeDia = 3.5
If oManuName = 3 then holeHDAngle = 90.0
If oManuName = 3 then holeHDDepth = 1.86
If oManuName = 3 then holeName = "C/Sunk Hole for M3 CSHS"

If oManuName = 4 then holeDia = 4.5
If oManuName = 4 then holeHDAngle = 90.0
If oManuName = 4 then holeHDDepth = 2.48
If oManuName = 4 then holeName = "C/Sunk Hole for M4 CSHS"

If oManuName = 5 then holeDia = 5.5
If oManuName = 5 then holeHDAngle = 90.0
If oManuName = 5 then holeHDDepth = 3.1
If oManuName = 5 then holeName = "C/Sunk Hole for M5 CSHS"

If oManuName = 6 then holeDia = 7.0
If oManuName = 6 then holeHDAngle = 90.0
If oManuName = 6 then holeHDDepth = 3.72
If oManuName = 6 then holeName = "C/Sunk Hole for M6 CSHS"

If oManuName = 8 then holeDia = 9.0
If oManuName = 8 then holeHDAngle = 90.0
If oManuName = 8 then holeHDDepth = 4.96
If oManuName = 8 then holeName = "C/Sunk Hole for M8 CSHS"

If oManuName = 10 then holeDia = 11.0
If oManuName = 10 then holeHDAngle = 90.0
If oManuName = 10 then holeHDDepth = 6.2
If oManuName = 10 then holeName = "C/Sunk Hole for M10 CSHS"

If oManuName = 12 then holeDia = 13.0
If oManuName = 12 then holeHDAngle = 90.0
If oManuName = 12 then holeHDDepth = 7.44
If oManuName = 12 then holeName = "C/Sunk Hole for M12 CSHS"

If oManuName = 16 then holeDia = 17.0
If oManuName = 16 then holeHDAngle = 90.0
If oManuName = 16 then holeHDDepth = 8.8
If oManuName = 16 then holeName = "C/Sunk Hole for M16 CSHS"

If oManuName = 20 then holeDia = 21.0
If oManuName = 20 then holeHDAngle = 90.0
If oManuName = 20 then holeHDDepth = 10.16
If oManuName = 20 then holeName = "C/Sunk Hole for M20 CSHS"

Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part

Set selection1 = partDocument1.Selection
selection1.Search "Type=Hole,sel"

For i=1 To selection1.Count
Set ohole1 = selection1.Item(i).Value


oHole1.Type = catSimpleHole

oHole1.ThreadingMode = catSmoothHoleThreading

oHole1.BottomLimit.LimitMode = catUpThruNextLimit

oHole1.Diameter.Value = holeDia

oHole1.Type = catSimpleHole

oHole1.Type = catCountersunkHole
oHole1.CounterSunkMode = catCSModeDepthAngle
oHole1.HeadAngle.Value = holeHDAngle
oHole1.HeadDepth.Value = holeHDDepth


'selection1.Item(i).Value.Name = holeName&intIndex ------- Can't get it to keep the instance number

Next

part1.Update

End Sub
 
Could someone tell me how I can get the code above to run at product level.
I have to open the part in a new window to make it work or it give me an error ?

LWolf, had a play with the code you sent and it’s starting to slowly make sense to me,
Cheers :)
 
Alan, here is something that works for a product, your selection is defined for it...
I also added, and commented away a way to get hold of a part in assembly...

Sub CATMain()
Dim oManuName
oManuName = 3 'InputBox("Enter Screw size M?")

Dim holeDia
Dim holeHDAngle
Dim holeHDDepth
Dim holeName
If oManuName = 3 Then holeDia = 3.5
If oManuName = 3 Then holeHDAngle = 90#
If oManuName = 3 Then holeHDDepth = 1.86
If oManuName = 3 Then holeName = "C/Sunk Hole for M3 CSHS"

Dim product1 As Product
Set product1 = CATIA.ActiveDocument.Product
Dim oSelection
Set oSelection = CATIA.ActiveDocument.Selection
oSelection.Clear

'Dim oPartProduct As Product
'Dim oPartDocument As Document
'Dim oPart As Part
'For Each oPartProduct In product1.Products
' Set oPartDocument = oPartProduct.ReferenceProduct.Parent
' Set oPart = oPartDocument.Part
oSelection.Search "Type=Hole,all"
'Next
For i = 1 To oSelection.Count
Set oHole1 = oSelection.item(i).Value
oHole1.Type = catSimpleHole
oHole1.ThreadingMode = catSmoothHoleThreading
oHole1.BottomLimit.LimitMode = catUpThruNextLimit
oHole1.Diameter.Value = holeDia
oHole1.Type = catSimpleHole
oHole1.Type = catCountersunkHole
oHole1.CounterSunkMode = catCSModeDepthAngle
oHole1.HeadAngle.Value = holeHDAngle
oHole1.HeadDepth.Value = holeHDDepth
oHole1.name = holeName & "." & i​
Next

product1.Update

End Sub


regards,
LWolf
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top