Wednesday, November 6, 2013

Drawing A Rectangle With AutoLISP 4

Function 1, 2, 3, And 4


I'm now going to talk about the first three functions of the AutoLISP program. Here is the explanation of the three functions.


Function 1


The AutoLISP program starts with a call to this function. The CMDECHO system variable is set to zero. I do not want command echos.


Next there is checked if there are entities in the drawing. If so, all these entities are deleted. We start with an empty screen.


(defun start ()
(setvar "cmdecho" 0)
(command "zoom" "all")
(setq p1 (getvar "vsmin")
p2 (getvar "vsmax")
)
(setq ss (ssget "c" p1 p2))
(if ss
(command "erase" "all" "")
)
)


Function 2


With the second function the dialog box is displayed. First a flag gets the value zero. The width and the height gets a value too.


After setting those values, there is the WHILE loop. There is stayed in the WHILE loop as long as the variable FL has the value zero.


The dialog box is loaded into the AutoLISP program and next the dialog box is displayed. There are the LOAD_DIALOG and the NEW_DIALOG functions.


The image is displayed. A slide is loaded into the AutoLISP program. The sizes of the image has been set. It is found in the DCL file.


The width and the height tiles get the value from before. The focus is set in the width tile. And values are entered.


The values that are entered plus the value of the flag and the scale are given back to the fucntion by the VALUE function.


Those values are stored in a list. The values in the list are found. Also the value of the flag variable.


(defun dlgbx (/ di fl hi ls nr oh th wd wi)
(setq fl 0
wd 300
ht 200
)
(while (= fl 0)
(setq di (load_dialog "c:/make/rectg.dcl"))
(new_dialog "rt" di)
(setq wi (dimx_tile "im")
hi (dimy_tile "im")
)
(start_image "im")
(fill_image 0 0 wi hi 0)
(slide_image -150 -150
(+ wi 150)
(+ hi 150)
"c:/make/rectg.sld"
)
(end_image)
(set_tile "wd" (itoa wd))
(set_tile "ht" (itoa ht))
(mode_tile "wd" 3)
(action_tile "accept" "(setq ls (value))
(done_dialog)"
)
(start_dialog)
(unload_dialog di)
(setq fl (nth 0 ls)
wd (nth 1 ls)
ht (nth 2 ls)
sc (nth 3 ls)
)
)
(list wd ht sc)
)


Function 3


Function 3 is the VALUE function. The second function makes a call to that function. The width and the height are found.


There is the CONDITION function. It is used to find the scale of the drawing. It checks the value of width and height.


But there is a maximum for the width and the height. If the width or the height is more than the maximum, a dialog box is displayed.


If the value of the width and the height is less than what is the maximum, then the FL variable gets the value of one.


The value of the flag, the width, the height, and the scale is pout in a lsit. And the list is given back to function 2.


(defun value (/ fl nr oh th wd)
(setq wd (atoi (get_tile "wd"))
ht (atoi (get_tile "ht"))
fl 0
)
(cond
((and (<= wd 350) (<= ht 250))
(setq sc 1)
)
((and (<= wd 700) (<= ht 500))
(setq sc 2)
)
((and (<= wd 1750) (<= ht 1250))
(setq sc 5)
)
((and (<= wd 3500) (<= ht 2500))
(setq sc 10)
)
)
(if (> wd 3500)
(alert "The maximum width is 3500")
)
(if (> ht 2500)
(alert "The maximum height is 2500")
)
(if (and (<= wd 3500) (<= ht 2500))
(setq fl 1)
)
(list fl wd ht sc)
)


Function 4


With this function the layers are set or they are created if they not exist. The TBLSEARCH function is used.


(defun chlay ()
(if (tblsearch "layer" "025")
(command "layer" "s" "025" "")
(command "layer" "m"
"025"
"c"
1
""
""
)
)
(if (tblsearch "layer" "050")
(command "layer" "s" "050" "")
(command "layer" "m"
"050"
"c"
3
""
""
)
)
(if (tblsearch "layer" "070")
(command "layer" "s" "070" "")
(command "layer" "m"
"070"
"c"
4
""
""
)
)
(if (tblsearch "layer" "dimensions")
(command "layer" "s" "dimensions" "")
(command "layer" "m"
"dimensions"
"c"
1
""
)
)
(if (tblsearch "layer" "text")
(command "layer" "s" "text" "")
(command "layer" "m"
"text"
"c"
2
""
""
)
)
)


Very good. I have talked about the first four functions of the AutoLISP prgoram. I have given an explanation about them.




Telling Others


Do you like what you have read? Do you know other people, that could be interested? Could you tell them about this blog?




Comment


In the mean time. If you have any questions. Or you want to tell me something. Feel free to add a comment to this blog.


I would love to hear from you. And when you come to me with a comment. I will give a reply to your question or remark.




Warning


Don't spend a lot of money on AutoCAD Light. It is only for creating 2D drawings and it doesn't support AutoLISP.


There is a very similar CAD program. And that is completely free. The name of the program? DraftSight.


How to get it? Do a search on Google for “download DraftSight”. And you will find where you can download the program.






Only Create Drawings


When your CAD operators don't create the borders of your drawings, a lot of time is saved. You get your drawings much faster.


I have created a program that does exactly that. An AutoCAD drawing has been created and the program draws a border around it.


If you want to see how the program works, go to YouTube. You'll find the working of the program here:


http://www.youtu.be/O8Zy6n9zS8Q


Now the AutoLISP program gives you the choice to select the size of your border. You can select A4, A3, A2, or A1.


Maybe you already know the size of the border of your drawing. Maybe all your drawings have the size A1. If so. Let me know.


That is important. The program finds the proper scale of your drawing. Or do you already know what the scale always is?


I can write the AutoLISP program that you want. The price? I will only charge you RM 600.-. That is less than US $ 200.-.






You are welcome to publish my article provided you include the resource box with links intact.




Resource Box


Jos van Doorn is an AutoLISP programmer and blogger. He is originally from Holland and now he lives in Malaysia.



He is the founder of the Make AutoCAD Fast business. Make AutoCAD Fast is writing AutoLISP programs for AutoCAD users.



Make AutoCAD Fast created an AutoLISP program for drawing a border around AutoCAD drawings. The program can be found on YouTube.
http://www.youtu.be/O8Zy6n9zS8Q



Jos is writing a blog. In it are AutoLISP programs with information and it is about Make AutoCAD Fast. You can find his blog here:


http://www.makeautocadfast.blogspot.com


Maybe you have a question. Or want to tell me something. You can contact me on this e-mail address:


makeautocadfast@ymail.com


This article may be freely reprinted or distributed in its entirety in any Ezine, newsletter, blog, or website. As long as the following resource box is added:


-------------------------------------------------
This article is written by Jos van Doorn. He is an AutoLISP programmer who has helped engineering firms and architects to get their AutoCAD drawings fast, without waiting for hours.


You can find more valuable information about his
business and AutoLISP at his blog. It is here:


http://www.makeautocadfast.blogspot.com


If you want to contact him. Go to his blog and leave a comment.
-------------------------------------------------


No comments:

Post a Comment