lownote1980 Posted August 13, 2010 Posted August 13, 2010 Hi all, I am in the process of writing my first Lisp routine which is very basic. I was aiming to have a lisp which when a user defined point was picked, would plot a point on a certain layer and the z value on another layer. I am a little stuck and could do with some guidance on where I have gone wrong if anyone could point me in the right direction. I have included comments next to the code to highlight what I thought I was programming! Thanks in advance Lownote tinlev.lsp Quote
Lt Dan's legs Posted August 13, 2010 Posted August 13, 2010 (defun C:tinlev (/ pt1 z) (setq pt1 (getpoint "\nSpecify point on tin: ") z (caddr pt1) ) (entmake (list (cons 0 "point")(cons 8 "cross")(cons 10 pt1))) (entmake (list (cons 0 "text")(cons 1 (rtos z))(cons 8 "detail")(cons 10 pt1)(cons 40 0.4))) (princ) ) Quote
Tharwat Posted August 13, 2010 Posted August 13, 2010 Here it goes according to your structure .... (defun C:tinlev (/ pt1 z) (setq pt1 (getpoint "\nPick point on TIN....") z (caddr pt1) ) (command "_.-layer" "_s" cross "" "") (command "_.point" pt1 ) (command "_.-layer" "_s" "lev" "" "") (command "_.text" "s" "DETAIL" "J" "MR" pt1 "0.4" "0" (rtos z 2 2 )) (princ) ) Any other changes just ask. Regards, Tharwat Quote
lownote1980 Posted August 13, 2010 Author Posted August 13, 2010 Thank you Lt Dans Legs and Tharwat. I can see the logic in the more macro based programming Tharwat. I am going to compare the macro functions against the Lisp functions to wor out what each cons parenthesis does. Kind regards Lownote Quote
Tharwat Posted August 13, 2010 Posted August 13, 2010 Thank you Lt Dans Legs and Tharwat. I can see the logic in the more macro based programming Tharwat. I am going to compare the macro functions against the Lisp functions to wor out what each cons parenthesis does. Kind regards Lownote Keep in mind that you can not use the command abbreviation in Lisp programming like you did with (dt) instead of (text) and (-la) instead of (-layer) ...... so on. Good luck. Quote
Lt Dan's legs Posted August 13, 2010 Posted August 13, 2010 (defun C:tinlev (/ pt1 z) (setq pt1 (getpoint "\nSpecify point on tin: ") z (caddr pt1) ) (entmake (list (cons 0 "point");;create a point (cons 8 "cross");;set the layer (cons 10 pt1);;set the insertion point ) );;set the insertion point (entmake (list (cons 0 "text");;create a text (cons 1 (rtos z));;content's of text (cons 8 "detail");;set the layer (cons 10 pt1);;set the insertion point (cons 40 0.4);;set the text height ) ) (princ) ) Quote
lownote1980 Posted August 13, 2010 Author Posted August 13, 2010 Thanks Lt Dans Legs, The net went down at work but attached is what I thought was going on with the coding. I couldn't get AutocAD to recognist the lisp past the insert point part but I'll try again later. I did manage to get a Lisp working for inserting set blocks defined by a .csv file entry so all was not lost! tinlev.txt Quote
Tharwat Posted August 13, 2010 Posted August 13, 2010 First All codes were explained well by Lt dan in post number 6. so there is no need to redescribe them again. Second you have two parantheses missed in your file tinlev.txt , check them out once again . ;picklev.lsp. Monumental as this is Lownote's first LISP application. (DEFUN C:tinlev (/ pt1 z) ;set local variables to be used ie.pt1 (setq pt1 (getpoint "\nPick point on TIN:") ;set value for pt1 by asking user to define z (caddr pt1) ;set value for variable 'z' is z coord of picked point ) ;close parenth and end define function (entmake (list (cons 0 "point")(cons 8 "cross")(cons 10 pt1))) ;makes an point entity (not sure what the list is for), assigns it to layer cross and assigns value of variable z (entmake (list (cons 0 "text"[color="red"])[/color] (cons 1 (rtos z))(cons 8 "lev"[color="red"])[/color] (cons 10 pt1)(cons 40 0.4))) ;makes an text entity, gives it the value of z, assigns it to layer lev, (not sure on cons 10 or cons 40) (princ) ; exits quietly ) ;closes last parenth Regards, Quote
Tharwat Posted August 13, 2010 Posted August 13, 2010 If you want to add a point, I think it's better to change or add the Sys Var 'pdmode' to your codes to be able to see the point clearly. Regards, Quote
David Bethel Posted August 13, 2010 Posted August 13, 2010 Here's something a bit more robust: [b][color=BLACK]([/color][/b]defun c: tinelv [b][color=FUCHSIA]([/color][/b]/ pt1 z[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]initget 1[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq pt1 [b][color=NAVY]([/color][/b]getpoint [color=#2f4f4f]"\nPick Point on TIN: "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq z [b][color=NAVY]([/color][/b]caddr pt1[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]entmake [b][color=NAVY]([/color][/b]list [b][color=MAROON]([/color][/b]cons 0 [color=#2f4f4f]"POINT"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cons 6 [color=#2f4f4f]"BYLAYER"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cons 8 [color=#2f4f4f]"CROSS"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cons 10 [b][color=GREEN]([/color][/b]trans pt1 1 0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cons 39 0.0[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cons 62 256[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]entmake [b][color=NAVY]([/color][/b]list [b][color=MAROON]([/color][/b]cons 0 [color=#2f4f4f]"TEXT"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cons 1 [b][color=GREEN]([/color][/b]rtos z 2 4[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cons 6 [color=#2f4f4f]"BYLAYER"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cons 7 [b][color=GREEN]([/color][/b]getvat [color=#2f4f4f]"TEXTSTYLE"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cons 8 [color=#2f4f4f]"0"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cons 10 pt1[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cons 11 pt1[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cons 39 0.0[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cons 40 [b][color=GREEN]([/color][/b]getvar [color=#2f4f4f]"TEXTSIZE"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cons 62 256[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] (initget) forces a user input, otherwise it would crash on an empty input POINT entities use only WCS point values. the (trans) call takes care of that Groups 6 39 & 62 all default to their current sysvar state, so it is a good habit to clearly call out their values or set their sysvar prior to calling the (entmake) Same with group 7, 8, 40 but their settings a little harder to configure. Using (command) with text can be tricky based on prior existence of any text. It requires 1 extra input ( for height ) when there aren't existing text entities in the dwg Using (command) takes some error checking for the current state of the layer. ie you cannot Set to a layer when it is using frozen or non existent. It is always good to see someone try to create a macro and then ask for help rather then the opposite Good luck! -David Quote
Tharwat Posted August 13, 2010 Posted August 13, 2010 A very tidy and complete work David. Best regards, Quote
lownote1980 Posted August 14, 2010 Author Posted August 14, 2010 Hi David Thanks for the explanations above. What defines the groups (or put another way what group number is assigned at each stage?) Regards Lownote Quote
Lee Mac Posted August 14, 2010 Posted August 14, 2010 Hi DavidThanks for the explanations above. What defines the groups (or put another way what group number is assigned at each stage?) Regards Lownote Hi Lownote, Here is a DXF Reference for you to thumb through: http://images.autodesk.com/adsk/files/acad_dxf1.pdf Or for 2000 (sometimes easier to navigate): http://autodesk.com/techpubs/autocad/acad2000/dxf/ Quote
David Bethel Posted August 14, 2010 Posted August 14, 2010 Here's an older ( R14 ) DXF reference in Windows help format. -David DXF_R14.ZIP Quote
BIGAL Posted August 16, 2010 Posted August 16, 2010 Just a couple of things there is a typo in Davids code getvat ? happens to all of us scratch the head why wont it work. Also the program itself is actually labelled wrong its actually getting an object point that makes up the 3d Tin surface ie some object at the TIN end point, to pick a random location on a TIN and return a Z value is completey different. TIN Triangular irregular network. Quote
KRBeckman Posted August 16, 2010 Posted August 16, 2010 Here's something a bit more robust: [b][color=black]([/color][/b]defun c: tinelv [b][color=fuchsia]([/color][/b]/ pt1 z[b][color=fuchsia])[/color][/b] [b][color=fuchsia]([/color][/b]initget 1[b][color=fuchsia])[/color][/b] [b][color=fuchsia]([/color][/b]setq pt1 [b][color=navy]([/color][/b]getpoint [color=#2f4f4f]"\nPick Point on TIN: "[/color][b][color=navy])[/color][/b][b][color=fuchsia])[/color][/b] [b][color=fuchsia]([/color][/b]setq z [b][color=navy]([/color][/b]caddr pt1[b][color=navy])[/color][/b][b][color=fuchsia])[/color][/b] [b][color=fuchsia]([/color][/b]entmake [b][color=navy]([/color][/b]list [b][color=maroon]([/color][/b]cons 0 [color=#2f4f4f]"POINT"[/color][b][color=maroon])[/color][/b] [b][color=maroon]([/color][/b]cons 6 [color=#2f4f4f]"BYLAYER"[/color][b][color=maroon])[/color][/b] [b][color=maroon]([/color][/b]cons 8 [color=#2f4f4f]"CROSS"[/color][b][color=maroon])[/color][/b] [b][color=maroon]([/color][/b]cons 10 [b][color=green]([/color][/b]trans pt1 1 0[b][color=green])[/color][/b][b][color=maroon])[/color][/b] [b][color=maroon]([/color][/b]cons 39 0.0[b][color=maroon])[/color][/b] [b][color=maroon]([/color][/b]cons 62 256[b][color=maroon])[/color][/b][b][color=navy])[/color][/b][b][color=fuchsia])[/color][/b] [b][color=fuchsia]([/color][/b]entmake [b][color=navy]([/color][/b]list [b][color=maroon]([/color][/b]cons 0 [color=#2f4f4f]"TEXT"[/color][b][color=maroon])[/color][/b] [b][color=maroon]([/color][/b]cons 1 [b][color=green]([/color][/b]rtos z 2 4[b][color=green])[/color][/b][b][color=maroon])[/color][/b] [b][color=maroon]([/color][/b]cons 6 [color=#2f4f4f]"BYLAYER"[/color][b][color=maroon])[/color][/b] [b][color=maroon]([/color][/b]cons 7 [b][color=green]([/color][/b]getvat [color=#2f4f4f]"TEXTSTYLE"[/color][b][color=green])[/color][/b][b][color=maroon])[/color][/b] [b][color=maroon]([/color][/b]cons 8 [color=#2f4f4f]"0"[/color][b][color=maroon])[/color][/b] [b][color=maroon]([/color][/b]cons 10 pt1[b][color=maroon])[/color][/b] [b][color=maroon]([/color][/b]cons 11 pt1[b][color=maroon])[/color][/b] [b][color=maroon]([/color][/b]cons 39 0.0[b][color=maroon])[/color][/b] [b][color=maroon]([/color][/b]cons 40 [b][color=green]([/color][/b]getvar [color=#2f4f4f]"TEXTSIZE"[/color][b][color=green])[/color][/b][b][color=maroon])[/color][/b] [b][color=maroon]([/color][/b]cons 62 256[b][color=maroon])[/color][/b][b][color=navy])[/color][/b][b][color=fuchsia])[/color][/b] [b][color=fuchsia]([/color][/b]prin1[b][color=fuchsia])[/color][/b][b][color=black])[/color][/b] (initget) forces a user input, otherwise it would crash on an empty input POINT entities use only WCS point values. the (trans) call takes care of that Groups 6 39 & 62 all default to their current sysvar state, so it is a good habit to clearly call out their values or set their sysvar prior to calling the (entmake) Same with group 7, 8, 40 but their settings a little harder to configure. Using (command) with text can be tricky based on prior existence of any text. It requires 1 extra input ( for height ) when there aren't existing text entities in the dwg Using (command) takes some error checking for the current state of the layer. ie you cannot Set to a layer when it is using frozen or non existent. It is always good to see someone try to create a macro and then ask for help rather then the opposite Good luck! -David Just something I noticed while reading this... In the "cons 7" of the second entmake it says "getvat" instead of "getvar". Just thought it might confuse rookies. Quote
David Bethel Posted August 16, 2010 Posted August 16, 2010 Good catch 2 for 2 on getvat. Typos happen when you don't proofread well ! -David Quote
KRBeckman Posted August 17, 2010 Posted August 17, 2010 Oops, didn't notice that the typo had already been pointed out... and trust me I know all about the lack of quality proofreading... I can't tell you how much time I've spent trying to figure out what's wrong with my code when it turns out to be a typo:oops: Also, how do you get your perenthesis to change colors for easier matching? Quote
David Bethel Posted August 17, 2010 Posted August 17, 2010 Sometimes I think typo is my middle name.... As to the color, I wrote this lisp routine a long time ago the converts the code from an AutoLisp file into BBC format. Then copy and paste that into the body of the message. -David lsp2bbc.ls.lsp Quote
KRBeckman Posted August 17, 2010 Posted August 17, 2010 Very cool. Are there any other advantages to BBC format? Quote
Recommended Posts
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.