Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X
Hi,
I'm using vba to modify points in a .prt file.
Up to now I can read their coordinates, but I cannot change them. I thought the lines in red would do the job, but VBA seems to not recognize this command...
Sub test()
Dim asynconn As New pfcls.CCpfcAsyncConnection
Dim conn As pfcls.IpfcAsyncConnection
Dim session As pfcls.IpfcBaseSession
Dim i As Integer
Dim model As IpfcModelItemOwner
Dim points As IpfcModelItems
Dim lepoint As IpfcPoint
Dim pointPosition As IpfcPoint3D
Dim PtName As String
Set conn = asynconn.Connect("", "", ".", 5)
Set session = conn.session
Set model = session.CurrentModel()
Set points = model.ListItems(EpfcModelItemType.EpfcITEM_POINT)
Set piece = model
For i = 0 To points.Count - 1
PtName = points(i).GetName
Cells(i + 1, 1) = PtName
Set lepoint = points.Item(i)
Set pointPosition = lepoint.point
points.Item(i).SetName ("toto_" & i)
pointPosition.Set(0, Xvalue)
pointPosition.Set(1, Yvalue)
pointPosition.Set(2, Zvalue)
Next i
For i = 0 To points.Count - 1
PtName = points(i).GetName
Cells(i + 1, 1) = PtName
Set lepoint = points.Item(i)
Set pointPosition = lepoint.point
Cells(i + 1, 2) = pointPosition.Item(0)
Cells(i + 1, 3) = pointPosition.Item(1)
Cells(i + 1, 4) = pointPosition.Item(2)
Next i
conn.Disconnect (2)
End Sub
Anyone with an idea on the subject?
Thanks
Ce message a été modifié par: CHARLES CHARBIT
Hi Charles,
don't know if you still need a solution.
But for all others who came here to look for a solution, here is mine:
Your attempt to get the coordinates of a point is absolutely correct, but you cannot set the new coordinates the same way because it depends on the references, especially the dimensions.
For excample:
Set a point onto an axis and intersecting with a plane
==> this point has coordinates xyz in relation to the main coordinate system, but there are no changeable dimensions available.
Set a point onto a plane and referencing two other planes having an offset to them
==> this point also has xyz coordinates, but there are only two dimensions for it.
==> normally this dimensions value is not one of the points coordinates, they are what they are referenced for
Only points created as points by coordinates have three dimensions corresponding to the coordinates.
I once did a programm for updating point clouds in Pro|E
In my excample, the user selects the feature/Modelitem and then the program updates its coordinates
For this it gets the array of dimensions of the feature and changes them.
Truly it's not very inteligent because it was only designed to update Point Clouds based on the main coordinate system. I don't have any checks how many dimensions belong to a single point... i knew it will be three.
Here some Code extracts:
Dim model As IpfcModelItemOwner
model = Session.CurrentModel
Dim pobj As IpfcModelItem
Dim sel As IpfcSelections
Dim selopt As IpfcSelectionOptions
selopt = (New CCpfcSelectionOptions).Create("feature")
selopt.MaxNumSels = 1
sel = Session.Select(selopt, Nothing)
pobj = sel.Item(0).SelItem
Dim dimensions As IpfcModelItems
dimensions = pobj.ListSubItems(EpfcModelItemType.EpfcITEM_DIMENSION)
For pointnr As Long = 0 To dimensions.Count - 1 Step 3
Dim dimension As IpfcBaseDimension
dimension = dimensions.Item(pointnr + xyz)
dimension.DimValue = NEWVALUE
Next
Hi Martin,
With the above mentioned program is it possible to create a new coordinate system, with reference to the default CSYS.
With Regards
Aghil M