Modifying the points in geometry set
Modifying the points in geometry set
(OP)
Hi all,
I use GSD to import about 100 points from excel,
now I want to modify the coordinates of the points,
so I am thinking if I can associate the geometry set to a text or excel,
which means I can edit the coordinates by text or excel.
What I really need is modifying the coordinates(or change another set of points), not importing.
Because I had some commands after the geometry set, so I can't import the set again, it will lead to an error.
Of course I can make a design table to store all coordinates, but that means almost 300 parameters.
Any good idea?
Thanks
I use GSD to import about 100 points from excel,
now I want to modify the coordinates of the points,
so I am thinking if I can associate the geometry set to a text or excel,
which means I can edit the coordinates by text or excel.
What I really need is modifying the coordinates(or change another set of points), not importing.
Because I had some commands after the geometry set, so I can't import the set again, it will lead to an error.
Of course I can make a design table to store all coordinates, but that means almost 300 parameters.

Any good idea?
Thanks





RE: Modifying the points in geometry set
then edit the macro to change XYZ of all points based on excel file
indocti discant et ament meminisse periti
RE: Modifying the points in geometry set
CODE -->
Sub Export_Points() Dim oActiveDoc As Document Set oActiveDoc = CATIA.ActiveDocument Set mySelection = oActiveDoc.Selection mySelection.Clear Dim Status As String Dim vFilter(0) vFilter(0) = "HybridBody" mySelection.Clear Status = mySelection.SelectElement2(vFilter, "Select Geometrical set", True) mySelection.Search "'Generative Shape Design'.Point,sel" iCount = mySelection.Count strFile = "c:\Alex\Report.txt" Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.CreateTextFile(strFile, True) ReDim myArray(2) For i = 1 To iCount Dim oSelElem As SelectedElement Set oSelElem = mySelection.Item(i) Set oSelElem1 = oSelElem.Value oSelElem1.GetCoordinates myArray myArray(0) = Round(myArray(0) / 25.4, 3) myArray(1) = Round(myArray(1) / 25.4, 3) myArray(2) = Round(myArray(2) / 25.4, 3) objFile.Write oSelElem1.Name & "," & Join(myArray, ",") & vbCrLf Next i End Sub______
Alex ,
RE: Modifying the points in geometry set
CODE -->
Sub Modify() Set objFSO = CreateObject("Scripting.FileSystemObject") strFile = "c:\Alex\Report.txt" Set objFile = objFSO.OpenTextFile(strFile) Do Until objFile.AtEndOfStream strLine = objFile.ReadLine vSplit = Split(strLine, ",", 4) Modify_Coords vSplit(0), vSplit(1), vSplit(2), vSplit(3) Loop objFile.Close End Sub Function Modify_Coords(ByVal Name As String, x, y, z) ReDim myArray(2) myArray(0) = x myArray(1) = y myArray(2) = z Dim oPart As Part Set oPart = CATIA.ActiveDocument.Part Dim oPoint As Object Set oPoint = oPart.FindObjectByName(Name) 'oPoint.SetCoordinates myArray Dim oX Set oX = oPoint.x oX.Value = x * 25.4 Dim oY Set oY = oPoint.y oY.Value = y * 25.4 Dim oZ Set oZ = oPoint.z oZ.Value = z * 25.4 End Function______
Alex ,
RE: Modifying the points in geometry set
______
Alex ,
RE: Modifying the points in geometry set
I have seen the code above, it worked well, and thanks for the movie!
Now another problem I meet is that if I want to add or remove some points in the geometry set, how?
since not every set has same numbers of points.
Can I make it by the changes of the text file?
for example
I have 100 points in the text file, and now I key point.101 in the text file,
which creates a point in catia automatically.
And if I want to remove a point.
Please tell me some advice or hints.
Thanks.
RE: Modifying the points in geometry set
indocti discant et ament meminisse periti
RE: Modifying the points in geometry set
but it's enough if I can get some useful tips here.
Some problems I can imagine, first, how to set name of new point,
second, how to make a spline based on a whole geometry set, so the spline can be made no matter how many points in it.
I haven't really done it, so if any advice on this, please tell me,
thanks
RE: Modifying the points in geometry set
the 2d script from Alex works as this
- open the txt file
- read 1 line
- split the line info (name,x,y,z)
- execute the function to move that pt to new coord
- read next line until end of file
the function works as this- assign X,Y,Z
- find CATIA point with name from file
- set new coord for the point
we can see that the function does not check if the point exist or not. it will actually fail if the point does not exist.we can use this to create the new point.
in VBA we cannot 'try' a function and see if it works, so we have to tell the system to continue if there is any error
on error resume next is the magic word, on error goto 0 will go back to normal mode (crash when error)
we can then check the error code if any:
if err.number = 0 then ... would let us do the action when all is fine
else if err.number <>0 then .... would let us do something else if the function does not find the named point.
check point to xyz macro in FAQ for on error resume next and err.number checking.
for the spline now,
you have the choice to create the spline with the point in the order of the file, or by name.
if you want it by name it is more difficult as you have to check name order and what if 2 points have same name...
let say we create spline with points as they come from the txt file.
What i would do is create a array and add the point one by one as they arrive and use that array to create the spline.
but array are not always good, list are sometimes better.
As VBA does not have list, you google it and find this
now we have something smart to use.
so add this class in your code and add points to the list as they come, maybe after you change the XYZ in the function, you can then create the spline with the list after the loop.
if you want to know how to create a spline with point, just record the macro in catia and read the code.
That should do.
indocti discant et ament meminisse periti
RE: Modifying the points in geometry set
after I import the points, I need to create splines and then loft those splines,
sometimes I also have commands like scaling or rotate in it,
so, if I really create a new a spline, that means the whole part should be done again,
that's why I can only modify the coords, I don't want the "name" to be changed
this is what I understand, if I am wrong please tell me
=====
Anyway, now I can create new points if its name doesn't be found in catia, by using the magic word you gave me
let me ask something more detailed,
when a new point comes from the text file, its name is automatically set,
how to create a point with name? and what if two points have the same name? is it possible?
and how about remove the point in geometry set if it is not used
(i.e I have less points than the points already exist in geometry set)
RE: Modifying the points in geometry set
You keep bringing valuable information one post after the other. You need to bring all that upfront even if, when you do your code, you go one step at a time. At least when you take some option, you know the downstream...
To resume:
In your CATIA file you have an undefined number of points supporting a defined(?) number of spline used in a loft.
You want ot be able to change the XYZ of any points easier than editing then one at a time in CATIA, like export to excel, edit in excel, then push back to CATIA.
You also want to be able to add a new point with a given name in a spline
And you want to be able to remove any point only if not used by any spline
Do you want to be able to add or remove spline also or reorder spline in the creation of the loft?
This is what you need to bring at the begining as one requirement might have large impact on your coding option.
Starting to code with no objective is the best way to create inefficient code.
indocti discant et ament meminisse periti
RE: Modifying the points in geometry set
first, I import 3 sets of points to catia, then do splines of each set,
totally I have 3 point sets, 3 splines, but number of points is uncertain, maybe 35, 40...
so I think it is convenient to separate them into 3 geometry sets.
second, I adjust the scales of 3 splines, then rotate an angle.
finally, use loft according to the 3 splines I adjust, and create solid model.
That's the process.
After this model is done, I want to see the results of different combination of points,
so I need a script or macro to simplify the repeated work.
And the order of splines won't be a problem if I can modify the whole set of points.