+ Reply to Thread
Page 1 of 4 1 2 3 ... LastLast
Results 1 to 10 of 37
  1. #1
    Junior Member
    Computer Details
    labmonkey's Computer Details
    Operating System:
    Windows 7
    Using
    AutoCAD 2010
    Join Date
    Aug 2009
    Location
    Japan
    Posts
    24

    Default Importing polygon from a csv file

    Registered forum members do not see this ad.

    Hello,

    I have searched through the forum and google, but I couldn't quite find the answer to this question, so I hope somebody here can help me.

    Is there a simple way to import a polygon from a csv file? I have read about ascpoint.lsp, but as far as I could work out, this makes a polyline, not a polygon. A simplified example is that I want to draw a rectangle with points 0,0 and 10,5 (note there is no z-axis, i.e. it's all just 2D). How can I create this from a csv file? I am flexible as to the format of the csv, but for example it could be
    0 0 10 5.

    Without trying to overcomplicate things, it would also be useful if the colour could be defined in the same csv file (e.g. using a 5th column, or a second row) and that the polygons were automatically filled solid (as you could do by using the BHATCH command).

    The main reason I ask is that I have some cel files containing polygons and lines, but I cannot import them into autoCAD directly (changing the extension to DGN and inserting it fails) possibly due to a weird/obsolete format, however, I can convert the cel file to a csv file and strip out the nonsense. If it helps I could add a copy of an example cel file to a reply to this thread.

    Many thanks in advance.

  2. #2
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,725

    Default

    Unless I’m missing something in your explanation, an AutoCAD rectangle is nothing more than a polyline.
    What information is stored in the said CSV? Is about the insertion point and dimensions of rectangle, or coordinates of the corners? You have more than one case described in a singe CSV or many CSV files?

    The easiest way to solve this will be to open the CSV file in Excel and build a script to automate the drawing operations:
    Code:
     _RECTANGLE 0,0,0 10,5 _HATCH _P _S _L  _CHPROP _L  _C 5
    Please pay attention that the line should end with an space character.

    Use SCRIPT command to run it.
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  3. #3
    Junior Member
    Computer Details
    labmonkey's Computer Details
    Operating System:
    Windows 7
    Using
    AutoCAD 2010
    Join Date
    Aug 2009
    Location
    Japan
    Posts
    24

    Default

    Mircea,

    Thank you so much for your reply. These forums are extremely useful when you don't know the best approach to solve the problem.

    Firstly, sorry, I realise my mistake with the polyline/polygon in ascpoint.lsp. I had set my csv file up so that it wouldn't close the polyline. I needed a 5th set of coordinates (with the 5th being the same as the first) so that it 'knows' to close the polyline, i.e. switch it from three lines, to a rectangle.

    Secondly, I think you're idea of the scrip is great. I will give it a go and reply to say if it works or not. Presumably this approach can be used to make multiple polygons in the same script? (To answer your question, yes there will be many polygons in my CAD file.)

  4. #4
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,725

    Default

    You may have how many lines/operations you want in the script:
    Code:
    _RECTANGLE 0,0,0 10,5 _HATCH _P _S _L  _CHPROP _L  _C 5 
    _RECTANGLE 15,9,0 20,17 _HATCH _P _S _L  _CHPROP _L  _C 2 
    _RECTANGLE -15,-9,0 -20,-17 _HATCH _P _S _L  _CHPROP _L  _C 7 
    _ZOOM _E
    ;end of script
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  5. #5
    Junior Member
    Computer Details
    labmonkey's Computer Details
    Operating System:
    Windows 7
    Using
    AutoCAD 2010
    Join Date
    Aug 2009
    Location
    Japan
    Posts
    24

    Default

    It really varies, it could be very many (more than one hundred).
    From your post I think it will not be difficult to generate this. I shall give it a go and post later to tell you how I got on (or to ask further questions).
    I'm in Japan, so I will have a bit of a break now, but will hopefully have time later to finish this.
    Thanks once again.

  6. #6
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,725

    Default

    You're welcome!
    I suggested you to use Excel (or other worksheet application for that mater) since there you have built-in features to clone the code from first line to all subsequent ones.

    There should be night at this time in Japan, right? It may be good to fill the location field in your Profile; didn't noticed yet another user from Japan.
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  7. #7
    Junior Member
    Computer Details
    labmonkey's Computer Details
    Operating System:
    Windows 7
    Using
    AutoCAD 2010
    Join Date
    Aug 2009
    Location
    Japan
    Posts
    24

    Default

    Will update my profile to make it up to date.
    To save me a little time, could you tell me how I could use the PLINE command?
    e.g. instead of
    Code:
    _RECTANGLE 0,0,0 10,5 _HATCH _P _S _L  _CHPROP _L  _C 5
    have
    _PLINE for the equivalent shape.
    Also, with your above code the lines are all the same colour (red, which I guess is the default). How may I change that?
    If you're busy, please don't worry, I think I can work it out for myself after dinner.
    (It's only 6pm here, but I think I will go home soon to eat and have another crack at this afterwards.)

    I honestly never knew you could use scripts in autocad. I get the feeling I may have saved a lot of time if I knew before.

  8. #8
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,725

    Default

    Just follow the succession of prompters for the desired command - you may test it first on command line; please pay attention to call command line version of commands with dialog boxes (i.e. "-HATCH" instead of "HATCH").
    To address your question:
    Code:
    _PLINE 0,0,0 10,0 10,5 0,5 _C _CHPROP _L  _C 3  _HATCH _P _S _L  _CHPROP _L  _C 5
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  9. #9
    Forum Deity
    Using
    Civil 3D 2013
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    4,542

    Default

    Also look at "read file" the same thing can be done without rewriting the csv to create a script using lisp you can read a line in work out the L & W and insertion pt and create a rectang or a pline, the lisp just keeps going till it hits end of file.

    How can I create this from a csv file? for example 0 0 10 5. A csv is a comma seperated variable file 0,0,10,5 you have a space delimited file, good news it doesn't matter just need to tell lisp to use space or ,

    Post a few lines of the csv
    A man who never made mistakes never made anything

  10. #10
    Junior Member
    Computer Details
    labmonkey's Computer Details
    Operating System:
    Windows 7
    Using
    AutoCAD 2010
    Join Date
    Aug 2009
    Location
    Japan
    Posts
    24

    Default

    Registered forum members do not see this ad.

    Mircea,

    I think I've almost got it now. I have one problem, summed up in this example script;
    Code:
    _LINE -96.860,32.583 56.082,32.583  _CHPROP _L  _C 2  _HATCH _P _S _L  _CHPROP _L  _C 1 
    _RECTANGLE -69.138,-14.067 -15.304,14.531 _CHPROP _L  _C 2  _HATCH _P _S _L  _CHPROP _L  _C 2 
    _COLOR 3 
    
    _MTEXT 10,15 _H 2 15,17 hello  
    
    _COLOR 6 
    
    _MTEXT 10,13 _H 2 15,15 hello  
    
    _PLINE -79.289,-229.289 -79.289,-200 20.711,-200 20,711,-229.289 _C  _CHPROP _L  _C 6  _HATCH _P _S _L  _CHPROP _L  _C 6 
    _ZOOM _E
    The last pline does not close. I thought that _C should close the line. As it is, it hangs as it is still looking for the next pline point. Any ideas? Am I missing some code?

    I think that is all I need to do script wise. I now have to decide the best way to generate the script, i.e. how to get the coordinates out of the existing *.cel file. Originally I was going to write a macro in excel, but there may be an easier approach. For your information, the *.cel file has lines like
    Code:
    SD 600000.000000;
    DZ TL-0.079289,-0.229289; TL-0.079289,-0.200000; TL0.020711,-0.200000; TL0.020711,-0.229289;
    where the numbers in the second line are coordinates for a pline. I think it will be relatively straightforward to do extract the useful information, but I'm not sure of the most efficient way of doing it right now. I will try in excel and see where that gets me. The number in the first line is related to the colour I'd want for the lines/bhatch, but that's beyond what I want to do now.

Similar Threads

  1. Importing from an SDF file
    By LispNovice in forum Map 3D
    Replies: 2
    Last Post: 29th Jul 2011, 01:48 pm
  2. Importing points from a .txt file
    By toddcl in forum CAD Management
    Replies: 5
    Last Post: 8th Dec 2010, 09:28 pm
  3. Polygon problem when importing into max 2010
    By Massimofraga in forum 3D Modelling
    Replies: 5
    Last Post: 18th Nov 2009, 01:16 am
  4. Importing a other formatted file
    By Vikes_Fl in forum AutoCAD General
    Replies: 3
    Last Post: 19th Aug 2009, 01:54 pm
  5. Importing a tiff file
    By Willis in forum AutoCAD Beginners' Area
    Replies: 2
    Last Post: 30th Oct 2008, 10:03 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts