Site Logo
Site Logo
 
It is currently Sun Apr 02, 2017 7:02 pm

All times are UTC [ DST ]




Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 
Author Message
 Post subject: From string(type) to points(type)
PostPosted: Wed Aug 31, 2016 11:35 pm 
Offline
DELCAM Guru
DELCAM Guru

Joined: Tue Nov 07, 2006 1:16 pm
Posts: 75
Hi,
I must open a text file that contains the Following Lines
27.5 12.4 27.3
12.2 34.5 43.3
ecc ecc ecc
i open the file with vb function system.io.file.readalllines that return a string() type
and after i use this Numbers to create a curve with Curves.CreateCurveThroughPoints but
this function accept a points() type and i can't convert from string() to points() !!

Thank's


Top
 Profile  
 
 Post subject: Re: From string(type) to points(type)
PostPosted: Mon Sep 12, 2016 5:07 pm 
Offline
DELCAM Staff
DELCAM Staff

Joined: Tue Mar 17, 2009 2:30 pm
Posts: 108
You can create a point by passing the string you have into the constructor:
Code:
New Delcam.Geometry.Point("10 5 6")

This would create a point at the specified location. Then put these into a list and pass them into the CreateCurveThroughPoints function.


Top
 Profile  
 
 Post subject: Re: From string(type) to points(type)
PostPosted: Mon Sep 12, 2016 11:05 pm 
Offline
DELCAM Guru
DELCAM Guru

Joined: Tue Nov 07, 2006 1:16 pm
Posts: 75
thank's but i've just tried this solution but the function "CreateCurveThroughPoints" accept only point type !!!
i've many string :
"22.5 27.5 25.3"
"21.7 22.2 26.9"
ecc...
ecc...
but this is string type and not point type ....
one solution it's use vb function split to have An Array (double type ) and to have
array(0) 22.5
array (1) 27.5
array (2)25.3
and after pass this array to the function.

is there a better way ?
Thank's


Top
 Profile  
 
 Post subject: Re: From string(type) to points(type)
PostPosted: Tue Sep 13, 2016 10:00 am 
Offline
DELCAM Staff
DELCAM Staff

Joined: Tue Mar 17, 2009 2:30 pm
Posts: 108
Yes, so you need to loop through your strings and create a list of Points. Then you pass that list into the function:

Code:
Dim listOfPoints = New List(Of Delcam.Geometry.Point)
For Each line As String in lines
    listOfPoints.Add(New Delcam.Geometry.Point(line))
Next

'' Now call CreateCurveThroughPoints with listOfPoints as a parameter


Top
 Profile  
 
 Post subject: Re: From string(type) to points(type)
PostPosted: Tue Sep 13, 2016 11:33 am 
Offline
DELCAM Guru
DELCAM Guru

Joined: Tue Nov 07, 2006 1:16 pm
Posts: 75
sorry,
i've tried this way:

Dim file As System.IO.FileStream
Dim Lines() As String
Dim listOfPoints = New List(Of Delcam.Geometry.Point)

file = System.IO.File.OpenRead(nomeFile)
lines = System.IO.File.ReadAllLines(nomeFile)

For Each line As String In Lines
listOfPoints.Add(New Delcam.Geometry.Point(line))
Next

psm.Curves.CreateCurveThroughPoints(CurveTypes.Bezier, listOfPoints)
End Sub

but there is an error :

Errore 7 Impossibile convertire il valore di tipo 'System.Collections.Generic.List(Of Delcam.Geometry.Point)' in 'Matrice a 1 dimensioni di Delcam.Geometry.Point'.

thank's !


Top
 Profile  
 
 Post subject: Re: From string(type) to points(type)
PostPosted: Tue Sep 13, 2016 12:09 pm 
Offline
DELCAM Staff
DELCAM Staff

Joined: Tue Mar 17, 2009 2:30 pm
Posts: 108
Try changing the line:
Code:
psm.Curves.CreateCurveThroughPoints(CurveTypes.Bezier, listOfPoints)


to:
Code:
psm.Curves.CreateCurveThroughPoints(CurveTypes.Bezier, listOfPoints.ToArray())


Top
 Profile  
 
 Post subject: Re: From string(type) to points(type)
PostPosted: Tue Sep 13, 2016 9:56 pm 
Offline
DELCAM Guru
DELCAM Guru

Joined: Tue Nov 07, 2006 1:16 pm
Posts: 75
sorry but this row
listOfPoints.Add(New Delcam.Geometry.Point(line))

return this error: Incorrect number of points found in line

line value is = "173.4725 81.5505 53.6597"

thank's !


Top
 Profile  
 
 Post subject: Re: From string(type) to points(type)
PostPosted: Thu Sep 15, 2016 9:17 am 
Offline
DELCAM Staff
DELCAM Staff

Joined: Tue Mar 17, 2009 2:30 pm
Posts: 108
That should work. Can you ensure that there are no leading or trailing spaces (use the Trim() method on the string). Also ensure that there are no double spaces between the point values.


Top
 Profile  
 
 Post subject: Re: From string(type) to points(type)
PostPosted: Thu Sep 15, 2016 10:38 am 
Offline
DELCAM Guru
DELCAM Guru

Joined: Tue Nov 07, 2006 1:16 pm
Posts: 75
i don't know
this code it'ok
Dim tmp As String = "25.6 12.5 36.5"
listOfPoints.Add(New Delcam.Geometry.Point(tmp))



In this code the add method return an error !!!!! but "line" contain the same data of tmp !!!!!!!!!!!!!

now line contain " 25.6 12.5 36.5 "
For Each line As String In Lines
line = Trim(line)
line = Replace(line, " ", "")
now line contain "25.6 12.5 36.5" the same of tmp !!! but the next row return an error " Incorrect number of points found in line" !!!
listOfPoints.Add(New Delcam.Geometry.Point(line))
Next


thank's


Top
 Profile  
 
 Post subject: Re: From string(type) to points(type)
PostPosted: Thu Sep 15, 2016 10:54 am 
Offline
DELCAM Staff
DELCAM Staff

Joined: Tue Mar 17, 2009 2:30 pm
Posts: 108
Surely the replace function will have removed the spaces between the values? So it won't match tmp


Top
 Profile  
 
 Post subject: Re: From string(type) to points(type)
PostPosted: Thu Sep 15, 2016 11:49 am 
Offline
DELCAM Guru
DELCAM Guru

Joined: Tue Nov 07, 2006 1:16 pm
Posts: 75
:oops: sorry !!!!

it remains a more space between number !!!!

Sorry !!!
Now it's ok


Top
 Profile  
 
 Post subject: Re: From string(type) to points(type)
PostPosted: Thu Sep 15, 2016 11:56 am 
Offline
DELCAM Staff
DELCAM Staff

Joined: Tue Mar 17, 2009 2:30 pm
Posts: 108
Great to hear that you got there!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB