Jump to content

Autocad drawing in dwg convert to lsp file


Danial

Recommended Posts

Is it possible that my whole drawing on autocad can be written into a lisp code in an easy way? Is there a way to convert dwg file into lsp? I really dont understand how to make the whole drawing with autolisp since i just want to type one command and the whole drawing appears. It may ask me for the arcs and the dimensions and when given with the provided information it can make the whole diagram. Please let me know a way or how i can do this. 

Link to comment
Share on other sites

Once you get the DWG, you can use ENTGET to transform an entity in a list of DXF codes. Yes, you could walk in the AutoCAD's database and transform the entities one by one. But probable you should include the nongraphic entities too. Say if a line must be placed on an inexistent layer, AutoCAD will create that layer "on the fly". But you must deal with text styles, dimstyles and so on. Also if there are inserts, you must define the blocks first. About the Xrefs -better don't even mention it.

To make the long story short: in theory it's possible, for some drawings it is easier, for other ones is more complicated.

  • Like 1
Link to comment
Share on other sites

Theoretically, you could generate a drawing with AutoLISP if you only needed to give it a few parameters.

 

It's a little trickier if you don't have AutoCAD to tweak the finished product, but you can use TrueView to check your work.

 

Without knowing more about the diagram you want to draw, we'd have trouble providing any more help than that. As mhupp suggests, it would be much easier to copy an existing drawing and modify it to suit your needs.

Link to comment
Share on other sites

Yes and no.

 

The first screenshot is pure LISP / VLA- / program generated, the user gets the dialogue box to input the data, here an electrical single line diagram / one line diagram and depending on the inputs the diagram is drawn. Code for this including the dialogue is about 1600 lines, plus there is coding to create the blocks in the diagram. I made this up one Christmas break to amuse myself and see if it could work. It can work well if as below the drawings follow a standard layout, we can use rules to create what we need to do. Something like a building layout, a road or similar where we need to consider the interaction between what we are interested in and the rest of the world become a lot more tricky. Then drafting become more an art than a science.

 

The no? No I can't share this.

 

image.thumb.png.28c5b16868ae2aacd59901dae1659e67.png

 

 

This mornings time filler was populating this, which uses the same blocks as above but with a nice dialogue interface - there are others out there too - each of these blocks are generated from code and the command is the text under the slide (example blkcb). The dialogue is about 600 lines and 2 lines of code for each entity in the blocks. My method here for coding all the blocks started with curiosity "minimum file size needed to draw something"... answer is via lisp file size is usually 50%+ of the dwg size.

 

image.png.6b63ec727e539584a8479b4c7a1b0e0e.png

 

 

I put how many lines in there as an appreciation that it can be a lot of coding to draw something via LISP.

 

 

Mine above are small databases for each entity, and these use 'entmake' to draw each part (or in the case of the SLD, some are generated on the fly), called each time you want to use them. Behind the lines there is code to generate layers, text styles and line types as required. 

 

Like MHUPPs link I have a small app that generates the code for each block when I want to add a new one to my database - makes things easier!

 

So yes it is possible, there is quite a bit to it though.

 

 

Edited by Steven P
Link to comment
Share on other sites

I don't know your LISP ability but maybe look at 'entmake', generate a small routine to draw basic entities to understand how that works, passing arguments to the function.

 

For example

(defun drawline (pt1 pt2 / result )
  (setq result (entmakex (list
    '(0 . "LINE")  ; entity type to make
    (cons 8 "0")  ; layer
    (cons 10 pt1) ; start point
    (cons 11 pt2) ; end point
  ))) ; end list, entmakex, setq
) ; end defun

 

is the basic code to draw a line from pt1 to pt2 - other entity types have different codes

 

This can be called with something like:

(drawline (getpoint "Select point 1") (getpoint "Select Point 2") )

 

 

Have a read, try to make up similar for other types and then all you need to do is draw the drawing!

 

As a hint I would copy and paste polylines and splines off an internet search

Link to comment
Share on other sites

Another Example: I wrote this back in the 90's (believe it or not) and still maintain it for drawing ANSI plug gages. It fully draws everything with Visual LISP. I Don't even use it anymore, but it's a good resource that I use as a test bed for trying out better code, and keeping myself exercised in LISP programming.

image.png.9c1cca2173d7d5a58b4004e5c0de1db3.png image.png.dcd5bcd47513ed200b578609f398a81c.png

image.thumb.png.dee57d5a809e4a6d21c60c37c7bc25e9.png

  • Like 2
Link to comment
Share on other sites

We need a sample dwg or 2 -3 to make realistic comments.

 

Like others have programs that draw objects like this house program but its like 100+ lisps so many different functions.

 

3dhouse.thumb.png.956c430c8bae97125ce124cb8c0c41d0.png

  • Like 1
Link to comment
Share on other sites

Your question has sparked some interest here, as Big Al asks, a few sample drawings and I am sure we can point you on your way or give you some code to use

 

 

 

Last example for now, adding a legend to drawings (command line "BlkJW", all done via LISP):

image.png.96dc1b8973395bc782beb8b737788892.png

  • Like 1
Link to comment
Share on other sites

Nice!

Once I wrote a Lisp to draw and simulate the work of an Enigma machine. Unfortunately I can't make it work. It draws the machine on the screen, but when it comes to encrypt a text... well... it works only on my computer -from others I got only bug reports :(

Anyway, that's an other example when there is nothing on the screen, the user starts a lisp and it makes the job.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...