Extract special coordinates
Extract special coordinates
(OP)
Hello, that's me again but for another question
I got some pipes where I need to extract some special coordinates.
I'm attaching a file to show what kind of pipes I have.
For the T, I need to extract the origin coordinates, the end coordinates and the branch coordinates.
For the other one, I would like to extract the intersection of the neutral fibers.
How can I make that?
Moreover, how can I extract the diameter?
Best regards
I got some pipes where I need to extract some special coordinates.
I'm attaching a file to show what kind of pipes I have.
For the T, I need to extract the origin coordinates, the end coordinates and the branch coordinates.
For the other one, I would like to extract the intersection of the neutral fibers.
How can I make that?
Moreover, how can I extract the diameter?
Best regards





RE: Extract special coordinates
I can write the rest by myself
RE: Extract special coordinates
indocti discant et ament meminisse periti
RE: Extract special coordinates
RE: Extract special coordinates
indocti discant et ament meminisse periti
RE: Extract special coordinates
Tesak
http://scripts4all.eu/txtoncurve/ - Curved text for Catia V5
RE: Extract special coordinates
I think the publication isn't automatic but made by the person who design the sketch, so if the person doesn't do it, that won't work I think.
Ok tesak, so it will be something like
Dim oPoint As GeometricElement
Sub GetCoordinates( CATSafeArrayVariant oPoint) ?
RE: Extract special coordinates
CODE --> vba
Sub GetAllSketchPoints() Dim doc, mySketches, mySketch, elements Set doc = CATIA.ActiveDocument Set mySketches = doc.Part.MainBody.Sketches Set mySketch = mySketches.Item(1) Set elements = mySketch.GeometricElements For i = 1 To elements.Count If elements.Item(i).GeometricType = catGeoTypePoint2D Then Dim coords(1) elements.Item(i).GetCoordinates coords MsgBox "Point coordinates are: " & coords(0) & "," & coords(1) End If Next End SubThis snippet will show you coordinates of all points in sketch.
Tesak
http://scripts4all.eu/txtoncurve/ - Curved text for Catia V5
RE: Extract special coordinates
And the global assembly has 250+ pieces, so I need to extract the information I need, no more. So I need those specific points of origin, end and branch.
The problem is: I don't know if the points in the sketcher will be in the same organized way from one part to another.
I thought about it after some tries and now I think the ideal solution would be to work on the surfaces directly.
I looked on the Automation file and I found some nice commands like GetOrigin, GetCenter, or GetOrigin, but on a part like this, I don't know how to organize my code
RE: Extract special coordinates
Maybe is better to give more details...how are those pipe parts done? Ribs with curves (for guide curve and profile) or curves/lines in 3D and sketches for profile) or in another way (imported solids without history)?
Even better, few samples uploaded here could make us understand how your assy is done. Is it CATIA v5 or v6?
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: Extract special coordinates
Tesak
http://scripts4all.eu/txtoncurve/ - Curved text for Catia V5
RE: Extract special coordinates
It is Catia V5-6R2014
I'm not saying that it will always be different and unique, I'm just considering the case where it would be the worst.
I started to write a code as a test to extract centers of faces in my solid, but it still is on "beta testing" because I picked some commands everywhere and put them together to have my own code
CODE --> CATScript
As you can see, this is mainly the code you can find in the Automation about PlanarFace, but I'm trying to implement code that will allow me to select automatically the faces and give me the center in an Excel File.
Moreover, I'm trying to make a loop that will select the part once at the time
Edit: Parts uploaded
RE: Extract special coordinates
RE: Extract special coordinates
Could it be possible if the macro automatically identified points in the center of Planar faces, and then at each point I would make a GetFirstPointCoordinates?
It is really frustrating that commands like GetCenter work only on circle or sphere and not on Planar faces...
RE: Extract special coordinates
CODE --> vba
Sub GetCenterPoint() Dim doc, sel, spa, ref, measurable Set doc = CATIA.ActiveDocument Set sel = doc.Selection Set spa = doc.GetWorkbench("SPAWorkbench") Set ref = sel.Item(1).Reference Set measurable = spa.GetMeasurable(ref) Dim coords(2) measurable.GetCenter coords MsgBox "Center coordinates are: " & coords(0) & "," & coords(1) & "," & coords(2) End SubTo run this example you have to preselect a circular edge on your part.
Tesak
http://scripts4all.eu/txtoncurve/ - Curved text for Catia V5
RE: Extract special coordinates
the script you're doing is big. if you don't use a smart logic it will be a mess.
I guess you already have the output of your script: create file with proper information / format from CATIA to other tubing app.
now define the input: will it be a product of part with dumb solid, solid from tubing workbench, just tubing run, user created tube geometry... define what is in scope what is not.
then process with logic from geometry to get the info then from info to output format. The logic to extract the info will be different from one input (tubing run) to another (user created geometry). Try to have the least interaction with the user, make the application smart : why would you ask the user to select a solid if there is only one in the file? (the logic definition would help you define smart opportunities).
for your standard parts I would search for edges in the solid then keep only circle one and get circle center, from that you can also get the normal direction if you need.
for the tube, if you use the tubing workbench and have the run, you should be able to get the points (and bend radius) from the run. If you don't have the run but used the tubing workbench you should be able to identify the sketch that define the tube center line and then get info from vertices or edges regarding the info you need.
When a code is playing with selection is might be wise to prevent user from interacting... pop up a modal form that eventually inform the user about the process evolution : found tube name xxx, processing points, found standard part name yyy, processing points... this could also help you !
indocti discant et ament meminisse periti
RE: Extract special coordinates
Here's my script
CODE --> CATScript
Indeed, I have to put some information of the part into another format
Here's the thing: there will be runs and dumb solids so Product all the time
The problem is: I already have a macro working fine with my runs (I succeeded to extract the nodes, the coordinates of each nodes, the diameter and the bend of my runs), so my problem is on the parts because of the different components of a piping circuit. Since I will have circuit with over 100 parts in it, I have to make an autoselection
Actually, I know some programming way, but it's the first time I have something this big to do.
I may have a way to do it in a global way, but the problem is, I don't have the details to do it, like commands (and the automation file is not the best to find infos)
So thanks to everyone trying to help me!
RE: Extract special coordinates
CODE --> vba
Sub CATMain() Dim doc, sel, spa, ref, measurable Dim inputObjectType(0) Set doc = CATIA.ActiveDocument Set sel = doc.selection Set spa = doc.GetWorkbench("SPAWorkbench") 'Selection of circular edge inputObjectType(0) = "TriDimFeatEdge" Status = sel.SelectElement2(inputObjectType, "Select the edge", True) If (Status = "cancel") Then Exit Sub Set ref = sel.Item(1).Reference Set measurable = spa.GetMeasurable(ref) sel.Clear Dim Coordinates(2) measurable.GetCenter Coordinates MsgBox "x = " & Coordinates(0) & " ; y = " & Coordinates(1) & " ; z = " & Coordinates(2) End SubTesak
http://scripts4all.eu/txtoncurve/ - Curved text for Catia V5
RE: Extract special coordinates
RE: Extract special coordinates
Dim Radius As Long
Set Radius = measurable.GetRadius
But it failed "GetRadius does not handle this property", but in the automation, it says that GetRadius works on circles.
And I tried Set Radius = measurable.Radius , same results.
Tried Dim oCoords(2)
measurable.GetCOG oCoords
Doesn't work too (I don't need the COG but just for test)
Did I forget something? Normally, it's on the measurable workbench and I called it before
I don't get why it works on GetCenter but not on GetRadius!
RE: Extract special coordinates
CODE --> vba
Tesak
http://scripts4all.eu/txtoncurve/ - Curved text for Catia V5
RE: Extract special coordinates
RE: Extract special coordinates
CODE --> CATScript
Sub CATMain() Dim intNbEdges As Integer Dim doc, sel, spa, ref, measurable Dim inputObjectType(0) Dim i As Integer Set doc = CATIA.ActiveDocument Set sel = doc.selection Set spa = doc.GetWorkbench("SPAWorkbench") 'Selection of circular edge inputObjectType(0) = "TriDimFeatEdge" Status = sel.SelectElement3(inputObjectType, "Select the edge", True, CATMultiSelTriggWhenUserValidatesSelection, True) If (Status = "cancel") Then Exit Sub intNbEdges = sel.Count For i = 1 To intNbEdges Set ref = sel.Item(i).Reference Set measurable = spa.GetMeasurable(ref) Dim Coordinates(2) measurable.GetCenter Coordinates Dim Radius As Long Radius = measurable.Radius MsgBox "x = " & Coordinates(0) & " ; y = " & Coordinates(1) & " ; z = " & Coordinates(2) & " ; radius = " & Radius Next End SubMoreover: the selection palette is useful but it doesn't take the TriDimFeatEdge with the selection palette. How can I make it automatically?
I thought about a objGCATIASelection0.Search "(CATLndSearch.TriDimFeatEdge),all" but it doesn't seem to work
RE: Extract special coordinates
indocti discant et ament meminisse periti
RE: Extract special coordinates
I presume the error is in the loop but where is the question... Do I need to reinitialize one of the variables? Like coordinates?
RE: Extract special coordinates
indocti discant et ament meminisse periti
RE: Extract special coordinates
indocti discant et ament meminisse periti
RE: Extract special coordinates
If I put a "on error goto 0", I will have to make a new selection, right?
RE: Extract special coordinates
so when you have something like an edge curve and want the circle center. you know circle center will fail if edge curve is not a circle so you do:
CODE -->
for i = 1 to x on error resume next create center point of edge (assuming it's a circle) if err.level <>0 then edge is not circle but system continue (resume next) if err.level = 0 then point is created = edge is circle on error goto 0 ' this will bring err.level to 0 and stop script if any error is found = back to normal behavior. nextindocti discant et ament meminisse periti
RE: Extract special coordinates
For the selection, do you have an idea about why the edges are not selected by the Tools Palette? I can't find anything about it on internet.
Also, I tried to automatize it, making a selection by the edges, but the command I tried (sel.Search "(CATLndSearch.TriDimFeatEdge),all" ) does not work that way. Do you have an idea about it?
The macro makes a selection of the part, then find all the edges and extract the wanted datas of all edges
RE: Extract special coordinates
Does anyone knows what are the items selected by the tools palette when you make
CODE --> CATScript
Because I can select the edges when I click on it but it's not included in the selection trap.
Same type of question with the command
CODE --> CATScript
I'm sorry to ask here again but I can't find those informations in the automation doc nor on the web
RE: Extract special coordinates
I tried "sel.Search("Type=TriDimFeatEdge, all")" but Method Search failed. So I wanted to add TriDimFeatEdge as a new support of search.
In automation it says that Add method will take an AnyObject, but when I wrote CATIA.ActiveDocument.Selection.Add(TriDimFeatEdge), still not working.
Do I have to put some line before? I know it's this hierarchy: AnyObject => Reference => Boundary => Edge => TriDimFeatEdge
RE: Extract special coordinates
- Selection of all the edges with sel.Search "Topology.CGMEdge,all"
- Selection of only the TriDimFeatEdge
RE: Extract special coordinates
Here is my loop to select the edges, that works alone
CODE --> CATScript
Sub CATMain() Dim intNbEdges As Integer Dim doc, sel, spa, ref, measurable Dim inputObjectType(0) Dim i As Integer Set doc = CATIA.ActiveDocument Set sel = doc.Selection Set spa = doc.GetWorkbench("SPAWorkbench") sel.Search "Topology.CGMEdge,all" intNbEdges = sel.Count MsgBox intNbEdges For i = 1 To intNbEdges Set myCircle = sel.Item(i) If myCircle.Type = "TriDimFeatEdge" Then On Error Resume Next Set ref = sel.Item(i).Reference Set measurable = spa.GetMeasurable(ref) Dim Coordinates(2) measurable.GetCenter Coordinates Dim Radius As Long Radius = measurable.Radius On Error Goto 0 MsgBox "x = " & Coordinates(0) & Chr(10) & "y = " & Coordinates(1) & Chr(10) & "z = " & Coordinates(2) & Chr(10) & "Diametre = " & 2 * Radius Err.Clear End If Next End SubAnd I've got my first macro that will select the pieces, which is this one:
CODE --> CATScript
'//---------- Get current selection & root product Set objGCATIASelection1 = objGCATIADocument0.Selection Set objGCATIAProduct1 = objGCATIADocument0.Product If objGCATIASelection1.Count = 0 Then objGCATIASelection1.Search "(CATLndSearch.Product),all" End If Err.Clear Dim objProduct As Product Dim objProductMat As Product Dim intNbParts As Integer Dim k As Integer intNbParts = objGCATIASelection1.Count For k = 1 To intNbParts Set objProduct = Nothing Set objProductMat = Nothing Set objProduct = objGCATIASelection1.Item(k).Value Set objProductMat = objGCATIASelection1.Item(k) Err.Clear Dim objInertia As Inertia 'On Error Resume Next Set objInertia = objProduct.GetTechnologicalObject("Inertia") Dim getMass As String getMass = objInertia.Mass Dim partName As String partName = objProduct.Name Dim Mat As Material Dim oManager As MaterialManager Set oManager = objProductMat.Item(k).GetItem("CATMatManagerVBExt") oManager.GetMaterialOnPart objProductMat.ReferenceProduct.Parent.Part,Mat matName = Mat.Name 'MsgBox matName Dim Coordinates(2) objInertia.GetCOGPosition Coordinates intGReportCurrentRow = intGReportCurrentRow + 1 InsertAnEXCELRowAt (intGReportCurrentRow) WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleMass, getMass WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitlePartName, partName WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleMaterial, matName WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleCOGX, Coordinates(0) & "mm" WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleCOGY, Coordinates(1) & "mm" WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleCOGZ, Coordinates(2) & "mm" Next intGReportCurrentRow = intGReportCurrentRow + 1 InsertAnEXCELRowAt (intGReportCurrentRow)But when I put the 1st one into the 2nd one, I don't succeed:
CODE --> CATScript
Sub CATMain() Dim objProduct As Part Dim objProductMat As Part Dim intNbParts As Integer Dim i As Integer Dim intNbEdges As Integer Dim doc, sel, spa, ref, measurable Dim inputObjectType(0) Dim j As Integer StartCATIA If Err.Number <> 0 Then Exit Sub End If StartEXCEL If Err.Number <> 0 Then Exit Sub End If Set objGCATIASelection0 = objGCATIADocument0.Selection Set objGCATIAProduct0 = objGCATIADocument0.Product If objGCATIASelection0.Count = 0 Then objGCATIASelection0.Search "(CATLndSearch.Part),all" End If intNbParts = objGCATIASelection0.Count For i = 1 To intNbParts Set objProduct = Nothing Set objProductMat = Nothing Set objProduct = objGCATIASelection0.Item(i).Value Set objProductMat = objGCATIASelection0.Item(i) Err.Clear 'On Error Resume Next Dim objInertia As Inertia On Error Resume Next Set objInertia = objProduct.GetTechnologicalObject("Inertia") Dim getMass As String getMass = objInertia.Mass Dim partName As String partName = objProduct.Name 'Dim Mat As Material 'Dim oManager As MaterialManager 'Set oManager = objProductMat.GetItem("CATMatManagerVBExt") 'oManager.GetMaterialOnPart objProductMat.ReferenceProduct.Parent.Part,Mat 'matName = Mat.Name Dim Coordinates(2) objInertia.GetCOGPosition Coordinates Set sel = CATIA.ActiveDocument.Item(i) Set spa = doc.GetWorkbench("SPAWorkbench") '// Now for the second loop sel.Search "Topology.CGMEdge,all" intNbEdges = sel.Count MsgBox intNbEdges For j = 1 To intNbEdges Set myCircle = sel.Item(j) If myCircle.Type = "TriDimFeatEdge" Then Set ref = sel.Item(j).Reference Set measurable = spa.GetMeasurable(ref) Dim oCoordinates(2) measurable.GetCenter oCoordinates Dim Radius As Long Radius = measurable.Radius MsgBox "x = " & oCoordinates(0) & Chr(10) & "y = " & oCoordinates(1) & Chr(10) & "z = " & oCoordinates(2) & Chr(10) & "Diametre = " & 2 * Radius Err.Clear End If WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleDepX, oCoordinates(0) & "mm" WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleDepY, oCoordinates(1) & "mm" WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleDepZ, oCoordinates(2) & "mm" Next intGReportCurrentRow = intGReportCurrentRow + 1 InsertAnEXCELRowAt (intGReportCurrentRow) WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleMass, getMass WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleMaterial, matName WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleCOGX, Coordinates(0) & "mm" WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleCOGY, Coordinates(1) & "mm" WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleCOGZ, Coordinates(2) & "mm" 'WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleDepX, oCoordinates(0) & "mm" 'WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleDepY, oCoordinates(1) & "mm" 'WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleDepZ, oCoordinates(2) & "mm" WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitlePartName, partName Next intGReportCurrentRow = intGReportCurrentRow + 1 InsertAnEXCELRowAt (intGReportCurrentRow) End Sub '/////////////////////////////////////////////////////////// CATMain