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!

Need help in scripting for selection of Points in specific Geo Set

Status
Not open for further replies.

Aviatorbarath

New member
Dec 27, 2012
35
US
How to selects the Elements (points) which is in Particular Geometric Set

selection1.Search "Name=Point'.'*,all"
'selection1.Search "type=CATGmoSearch.Point,all"

The above 2 option i tried but it gives selection of all points available in the active sheet. I jus want point selected from a specific geometric set

Does anyone have solution for this

Thanks
Barath :)
 
Replies continue below

Recommended for you

Hi
I tried that; but tht is not working.Any other solution can u provide

Thanks
Barath
 
Hi,

What Nick wanted to say is that you need first to do a selection (the GS) and then search inside that selection....

Code:
Sub CATMain()

Dim oPartDoc As Part
On Error Resume Next
Set oPartDoc = CATIA.ActiveDocument.Part  
  
If Err.Number <> 0 Then                 
Message = MsgBox("Sorry, This script works with a CATPart as Active document", vbCritical, "Error")
Exit Sub
End If

    ' What do you want to select - in this case a Geometrical Set
    Dim EnableSelectionFor(0)
    EnableSelectionFor(0) = "HybridBody"

    ' Reset the Selection
    Set sSEL = CATIA.ActiveDocument.Selection
    sSEL.Clear

 ' Define Selection
	MsgBox "Please Select the Geometrical Set where you have the POINTS"
    UserSelection = sSEL.SelectElement2(EnableSelectionFor, "Please select another Geometrical Set", False)
  
    ' Evaluation if the selection is correct or not
    If UserSelection <> "Normal" Then
        MsgBox "Error with the selection"
        Exit Sub
Else

Set ohybridbody = sSEL.Item(1).Value
    End If
Set partDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = partDocument1.Selection

selection1.Search "CATPrtSearch.Point,sel"

End Sub

Regards
Fernando

 
Thanks Fernando and Ntweison.

I didn notice that "*.Sel' in that code

This code worked :D.. Actually i dont wanna select the geometric set manually and do it. Rather i know the name of the geometric set. I want both the selection to be done automatically.. Any suggestions


Thanks
Barath :)
 
Use
If you know the GS name and sure about the presence of it(only once) (If more then the this method will return first accessed one i think... try it out)

CATIA.ActiveDocument.Part.FindObjectByName(GSName)

Selection.Add Part.FindObjectByName(GSName)
Selection.Search "Name=Point'.'*,sel"

Loop through all the points selected.

Regards,
Maddy

The willingness to share knowledge does not make one charitable; it makes one self-reliant to know more.
Modified - Courtesy of Robert Brault
 
Hi Maddy

I tried tht; it doesnt work. Actually i have some points int the geometric set named " Geometric Set_Points". i want to extract the coordinates of these points and save it in text or excel. so i wanna select the GS automatically and its points.. so after that some loop to get coordinate for each point in the set

thanks
Barath
 

Then try this..

Set oGS = Part.FindObjectByName("Geometric Set_Points")
' MsgBox oGS.Name & " Total Items : " & oGS.HybridShapes.Count ' For confirmation that you got it right.

For Each oPoint in oGS.HybridShapes
If TypeName(oPoint) = "HybridPointTangent" Then
' get the coordinates here using measure option
End If
Next

use the following filter option to get only 3D points out of all the contents of GS.
' HybridPointTangent = Point on curve option
HybridShapePointExplicit = isolated point
HybridShapePointCoord
HybridShapePointOnPlane
HybridShapePointOnSurface
HybridShapePointCenter
HybridShapePointTangent or ' HybridPointTangent i suppose
HybridShapePointBetween

Try with hybridshape and hybridpoint and see the result.. i cant recall completely.



Regards,
Maddy

The willingness to share knowledge does not make one charitable; it makes one self-reliant to know more.
Modified - Courtesy of Robert Brault
 
HI
i have extracted the poit coordinate by selectiong the Geometric set and the poitns in it automatically..but now the problem is. i want to extract the coordiante of the point with respect to local axis system.. Any suggestion to define local axis system, so tht i can get the coordinate of the point wrt that..
This is the code for which i need to add local axis system...Any suggestions

Sub CATMain()

Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
Set hybridShapeFactory1 = part1.HybridShapeFactory
Set objNetwork = CreateObject("Wscript.Network")
Set hb1=CATIA.ActiveDocument.Part.InWorkObject
Set hsf=CATIA.ActiveDocument.Part.HybridShapeFactory
Set prt=CATIA.ActiveDocument.Part
Set sel=CATIA.ActiveDocument.Selection
Set SPAWorkBench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")
Set planeZX = CATIA.ActiveDocument.Part.OriginElements.PlaneZX


If Err.Number <> 0 Then
Message = MsgBox("Sorry, This script works with a CATPart as Active document", vbCritical, "Error")
Exit Sub
End If

' Reset the Selection
Set sSEL = CATIA.ActiveDocument.Selection
sSEL.Clear


set FileSys = CATIA.FileSystem

Dim FileObj
Set FileObj = FileSys.CreateFile("D:\pointsout.txt", True)

set TextStr = FileObj.OpenAsTextStream("ForWriting")



Dim selection1
Set selection1 = partDocument1.Selection
Selection1.Add Part1.FindObjectByName("Geometric_Set_Points")
Selection1.Search "CATPrtSearch.Point,sel"

Dim Coord(2)
For i = 1 To Selection1.Count
Dim CurrWorkbench
Set CurrWorkbench = partDocument1.GetWorkbench("SPAWorkbench")
Dim Measure
Set Measure = CurrWorkbench.GetMeasurable(Selection1.Item(i).reference)
Msgbox Measure.Name
Measure. GetPoint Coord
Msgbox Coord(0) & ", " & Coord(1) & ", " & Coord(2)
TextStr.Write(Coord(0) & ", " & Coord(1) & ", " & Coord(2) & vbCrLf)


Next

part1.Update
End Sub

 
Use

Get the coordinates of Axis system using GetOrigin iAxisSystemXYZ
Get the vectors of the Axis system using GetVectors you will get X,Y (like 1,0,0 & 0,1,0)
and do a crossproduct to get normal vector i.e Z (0,0,1)

Multiply Sign of X with iAxisSystemXYZ(0) Coord of Axis system
Multiply Sign of Y with iAxisSystemXYZ(1) Coord of Axis system
Multiply Sign of Z with iAxisSystemXYZ(2) Coord of Axis system

Add This resultant values of X,Y,Z to Point coordinates to get the coordinate w.r.t axis system.
Pt(0) + iAxisSystemXYZ(0)*Sgn(x)
Pt(1) + iAxisSystemXYZ(1)*Sgn(y)
Pt(2) + iAxisSystemXYZ(2)*Sgn(z)


Regards,
Maddy

The willingness to share knowledge does not make one charitable; it makes one self-reliant to know more.
Modified - Courtesy of Robert Brault
 

Get the coordinates of Axis system using GetOrigin iAxisSystemXYZ
Get the vectors of the Axis system using GetVectors you will get X,Y (like 1,0,0 & 0,1,0)
and do a crossproduct to get normal vector i.e Z (0,0,1)

Multiply Sign of X with iAxisSystemXYZ(0) Coord of Axis system
Multiply Sign of Y with iAxisSystemXYZ(1) Coord of Axis system
Multiply Sign of Z with iAxisSystemXYZ(2) Coord of Axis system

Add This resultant values of X,Y,Z to Point coordinates to get the coordinate w.r.t axis system.
Pt(0) + iAxisSystemXYZ(0)*Sgn(x)
Pt(1) + iAxisSystemXYZ(1)*Sgn(y)
Pt(2) + iAxisSystemXYZ(2)*Sgn(z)


Regards,
Maddy

The willingness to share knowledge does not make one charitable; it makes one self-reliant to know more.
Modified - Courtesy of Robert Brault
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top