• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

import files to solidwork

  • Thread starter Thread starter Jonny123
  • Start date Start date

Jonny123

Guest
Good morning, everyone!
I have a little problem, although I have done the research, and having navigated to find solutions, in the end I have not solved anything yet.
So the problem is this, for my thesis I have to do and learn how to make 3d drawings, to make them I must be able to exploit some files generated by matlab with solidworks (I have premium 2009).
To be precise, I have a set of .pts files in a folder that I have to import into sw to create a template....how do you do?

thank you very much for every help
 
I press that I don't know if sw can interface with matlab...I assume you but I can't tell you how!
in general it is very simple to interface sw with a data table of excel, which however should be formatted correctly and be linked to the part/assieme.
your .pts file what kind of output is?what does it contain? dot coordinates or anything?
 
Hi, Michael.
first of all thank you!
therefore,opening the file with pts extension inside there are a series of x,y,z coordinates of a wing profile.
consider that I have something like 200 pts files, one for each section, with within each one a series of colored values related to each one's axis. .
Now it is about turning those points into a 3d drawing... although having done the tutorials I found nothing about it
 
Hi.

you need to rename your .pts files in .txt, then from solidworks you need to create curves through xyz points (icon next to reference geometries).
In this way you create curves in space that you can then use to make lofts.
the format of the files of the points must be of type:
x1,y1,z1
x2,y2
x3,z3
and so forth

wave
 
Okay thank you... I think I understand, even if I have only one doubt
as I said I have 200 sections, so 200 pts files to rename. . .in each of which there are 3 columns with each one a x number of elements.
I have to take every column for each pts and paste it into excel
or
create a curve with each of the pts?
Thank you.

cmq I will do some tests and I will know
 
you have to make a file for each curve, import each file individually to create 200! curves and then go to a loft. you don't need excel!
If you need to change the format because it is not suitable for solid works I recommend you use a text editor.
to rename the files, provided that they are in name order, you can rename them globally with windows.
If you select them all and right-click >rename, call the first for example section(1).txt all others are called in automatic section(2).txt, section(3).txt and so on.
I have the doubt that 200 sections are too many and that the loft coming out will present drafts. but you have to see this. normally, less sections have a loft is softer, because it is not forced to pass through points
 
Thank you very much!
Being a solidwork novelty to understand 100% I need to do some tests and physically see what I'm doing.
cmq the explanation is very clear and I do not think I have problems.
In any case I reserve myself to audit, I see how it goes with 200 and in case I climb for other tests!
soon then and again thanks
 
what they told you is perfect, remember only to use as a marker of separation "." and not ","
I don't remember what you use matlab, in case you replace them
 
so boys
I created these famous txt files and slew with the sw I managed to pull out a nice and clean design of my profile.
pee wave: I used 4 sections,also because 200 were too many:) tomorrow I will try with a number of sections increasing up to a 50ina and see if the design improves.

Thank you all!
 
As for delimiters, to answer the bagaroz post, depends on how you set the international windows settings.
Italian standards use the "," for the decimal and therefore use the "." to separate the fields. I and I also believe most people who often use text files, output from fem and things like this, imposed as a decimal separator the point "." as well as the English convention. this to be able to import into excel and other output programs directly created by nastran. I highly recommend it, because you interface better with all those foreign programs that use this convention.

wave
 
As for delimiters, to answer the bagaroz post, depends on how you set the international windows settings.
Italian standards use the "," for the decimal and therefore use the "." to separate the fields. I and I also believe most people who often use text files, output from fem and things like this, imposed as a decimal separator the point "." as well as the English convention. this to be able to import into excel and other output programs directly created by nastran. I highly recommend it, because you interface better with all those foreign programs that use this convention.

wave
Thank you, I wasn't aware that you could change the convention and that at that point the software used it. I have always exported to known block and then used the replace function....
 
hello to all, I send this thread to avoid opening a new one too similar.
for my thesis I find myself having to do a job completely similar to that of jhonny123. reading here I found how to import my matlab data into solidworks and of this I thank all those who have responded, but for now quite ingnoring about this software I wonder if there is a shortcut to import many curves from as many files in a single stroke, without having to perform the operation once at a time.
I tried to select multiple files from the import tool but it seems not to work, in fact it is possible to open a file at a time.
if someone has an alternative solution and was so kind to explain it in detail to him very grateful:redface:
 
you can create a macro of solidworks that matters files.
if you call files for example xxx1.txt; xxx2.txt xxx3.txt etc and then make a macro with a cycle from 1 to n that import files you save work.
Unfortunately, I can't help you in creating the macro because I've never done it in solid works, but it shouldn't be very different from doing it in excel. I recommend you register the macro and make an import of a file, then go edit it and thread a for-next cycle.
 
you can create a macro of solidworks that matters files.
if you call files for example xxx1.txt; xxx2.txt xxx3.txt etc and then make a macro with a cycle from 1 to n that import files you save work.
Unfortunately, I can't help you in creating the macro because I've never done it in solid works, but it shouldn't be very different from doing it in excel. I recommend you register the macro and make an import of a file, then go edit it and thread a for-next cycle.
thanks for the prompt response, I will try to understand how macros work in solidworks
 
I tried to record the macro, but unfortunately within the code then already the coordinates appear and not the procedure for their import (I hope you understand what I mean) someone would know how to help me in creating this macro or maybe pointing out where to find the necessary information
 
you have to read the files to the macro, assign each value to a variable and then write the point, e.g.

[Bleep] [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep] [Bleep [Bleep [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep] [Bleep] [Bleep [Bleep [Bleep] [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep
r:\temp\swx7900\macro1.swb - macro recorded on 03/05/10 by user
[Bleep] [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep] [Bleep [Bleep [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep] [Bleep] [Bleep [Bleep [Bleep] [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep
dim swapp as object

dim part object
dim boolstatus as boolean
dim x as single
dim y as single
dim z as single
dim longstatus as long, longwarnings as long

sub main()

set swapp = application.sldworks

set part = swapp.activedoc
dim mymodelview as object
set mymodelview = part.activeview
mymodelview.framestate = swwindowstate_e.swwindowmaximized
part.insertcurvefilebegin
open "c:\txt.txt" for input as #1 ' opens the file for input.
do while not eof(1) ' repeats until the end of the file.
input #1, x, y, z' reads data in variables.
boolstatus = part.insertcurvefilepoint(x, y, z)
loop
close #1 ' closes the file.
boolstatus = part.insertcurvefileend()

end
End of the macro!!! !


This macro reads a file called txt.txt consisting of values expressed in meters separated by a comma.
if it makes a loop over the loop for the number of files you need you are fine
 
(Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Ble
r:\temp\swx7900\macro1.swb - macro recorded on 03/05/10 by user
(Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Bleep) (Ble
dim swapp as object
dim part object
dim boolstatus as boolean
dim x as double
dim y as double
dim z as double
dim n as integer
dim n_file as integer's number of files to import
dim name as string ' file name to be combined with number
dimnamefile as string 'name of the combined file
dim longstatus as long
dim longwarnings as long

sub main()

set swapp = application.sldworks
set part = swapp.activedoc
dim mymodelview as object
set mymodelview = part.activeview
mymodelview.framestate = swwindowstate_e.swwindowmaximized
'
'
n_file = 5' number of files to import to import + or -
name = "c:\points" 'initial name full path of the file to be imported
I'm doing sketch 3d here.
for n = 1 to n_file
filename = name & " (" & n & ").txt" ' the end file name appears as "c:\points (1).txt"
'
open filename for input as #1 ' opens the file for input.
'
part.sketchmanager.insert3dsketch true
dim skpoint as object
do while not eof(1) ' repeats until the end of the file.
input #1, x, y, z' reads data in variables.
set skpoint = part.sketchmanager.createpoint(x, y, z)
part.sketchaddconstraints "sgfixed"
loop
part.clearselection2 true
part.sketchmanager.insertsketch true
boolstatus = part.extension.selectbyid2("point1@origin", "extsketchpoint", 0, 0, false, 0, nothing, 0)
close #1 ' closes the file.

'
'I now create curves
for n = 1 to n_file
filename = name & " (" & n & ").txt" ' change this line to change the file name to import
'
part.insertcurvefilebegin
open filename for input as #1 ' opens the file for input.
do while not eof(1) ' repeats until the end of the file.
input #1, x, y, z' reads data in variables.
boolstatus = part.insertcurvefilepoint(x, y, z)
loop
close #1 ' closes the file.
boolstatus = part.insertcurvefileend()

end


I have a little changed for your needs. (it was actually convenient to me and I lost some time).
now reads a number of files depending on the value input to the variable 'n_file'
the files must be called 'points (1).txt'; 'points (2).txt'
I called them this way because if you select all your files and rename them all together windows rename them in this way.
the macro creates sketches3d with inside the points and then creates the curves.
3d curves and sketches are completely untied between them, at the end of the execution if you don't need to see where the points are you can throw 3d sketches.
in truth you could also make the curves through 3d sketches, but they are not so deep in the macros of solidworks and I do more to make them.
Hi.

wave
 
Thank you very much, very kind. I have a single problem by running your script, properly changing file paths start importing points, but at some point from run-time error '62' (input beyond the end of the file) and performing the debug highlights me this line -> input #1, x, y, z' reads data in variables.
I think the problem is in the format where the coordinates are written in the text file. going to open it with the text editor and not with matlab I realize that the coordinates of each point have no spacers between them (opening the file in matlab each point was in a row to itself).
I wanted to make a past copy of one of the files here, but as by magic if I do the points return to being each on his line, then I attach the file. Do you have any idea if that's the problem? in case you could attach an example of text files in the correct format so I try to change the output of my matlab program?
I thank you again and hope not to be inappropriate or annoying
 

Attachments

depends on the fact that your file does not show the end line in the correct way.
normally to make an end line you must insert two invisible characters that are the carriage return (code ascii 13) and the line feed (code ascii 10).
if you open your document with notepad, missing the carriage return, the program does not include the end line and put a square for instead of the line feed, marking all the values below.
Similarly, my code searches after each set of coordinates the pair of characters ascii 13,10; finding only the character ascii 10 does not work and error.
I don't know why from matlab save the coordinates in this way, you have to see what kind of code you use for the text file, or write a vb routine or other to enter an ascii code 13 before each code ascii 10.
to view the problem I recommend you open the file with notepad++ (free program downloadable from the internet) and activate the option below view : show end line.
wave
 
your file is in unix format and must be converted into windows format.
Notepad++ can do this (if you can't save from matlab in the correct format).

under modification> converts fine line character>formed windows

in this way it transforms all the files with the due final characters.

Hi.

wave
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top