Jump to content

Add ATTDEF (Atribute) to an creating object.


mitchellrodhous

Recommended Posts

Well Back again with a problem were a solution is needed.

 

I'am drawing 3d solid objects by using LISP. For example the code below.

 

Now this lisp allows me to draw 4 boxes.

I wonder if it is posseble to give thoose boxes all their own attributes.

 

 

For example:

 

"box" p1 p6 h has the attributes of:

 

Name: *****Given by an code in LISP for example "TOP"

Length: ******The total Length calculated by two points I could create under setq.....

Width: * The total Widht calculated by two points I could create under setq......

Thickness: * The total Thickness I'll give under setq m.

 

Then after creating the boxes, I could click on the solid object and the attributes are present under my quick properties.

 

Wonder if this would be posseble?

 

Regards MR

 

 

 

(defun c:kast ()
 ;MR. CAD
 ;Autocad The Netherlands 
 ;define the function
 ;*
 ;Save System Variables
 (setq oldsnap (getvar "osmode"))

 ;save snap settings
 (setq oldblipmode (getvar "blipmode"))
 ;save blipmode setting
 (setvar "cmdecho" 1)
 ;*
 ;Switch OFF system Variables
 (setvar "osmode" 0)
 ;Switch OFF snap
 (setvar "blipmode" 0)
 ;Switch OFF Blipmode
 ;*

 ;get User Inputs
 ;get User Inputs
 (setq b (getdist "\nWidth of the cabinet : "))
 ;Width of the cabinet

 (setq h (getdist "\nHight of the cabinet : "))
 ;Hight of the cabinet
 (setq d (getdist "\nDepth of the cabinet : "))
 ;Depth of the cabinet
 (setq m (getdist "\nMaterialthickness of the cabinet : "))
 ;Materialthicknes of the cabinet
 ;*
 ;Get Insertion Point
 (setq ip (getpoint "\nInsertion Point : "))
 ;get the insertion point
 (setvar "osmode" 32)
 ;switch ON snap
 (setvar "osmode" 0)
 ;switch OFF snap
 ;*

 ;Start of Polar Calculations
 ;This are calculation made by MR Cad
 (setq p1 (polar ip (dtr 0.0) 0.0))
 (setq p2 (polar p1 (dtr 0.0) m))
 (setq p3 (polar p1 (dtr 0.0) b))
 (setq p4 (polar p3 (dtr 180.0) m))
 (setq p5 (polar p1 (dtr -90.0) d))
 (setq p6 (polar p5 (dtr 0.0) m))
 (setq p7 (polar p5 (dtr 0.0) b))
 (setq p8 (polar p7 (dtr 180.0) m))
 (setq p9 (list (car p1) (cadr p1) (+ (caddr p1) m)))
 (setq p10 (list (car p4) (cadr p4)(+ (caddr p4) m)))
 (setq p11 (polar p9 (dtr -90.0) d))
 (setq p12 (polar p10 (dtr -90.0) d))
 (setq p13 (list (car p2) (cadr p2) (+ (caddr p2) h)))
 (setq p14 (list (car p4) (cadr p4)(+ (caddr p4) h)))
 (setq p15 (polar p13 (dtr -90.0) d))
 (setq p16 (polar p14 (dtr -90.0) d))
 (setq p17 (list (car p13) (cadr p13) (- (caddr p13) m)))
 (setq p18 (list (car p14) (cadr p14) (- (caddr p14) m)))
 (setq p19 (list (car p15) (cadr p15) (- (caddr p15) m)))
 (setq p20 (list (car p16) (cadr p16) (- (caddr p16) m)))

 ;End of the Polar calculations by MR. CAD
 ;*
 ;Start Command Function
 (command "_-view" "_swiso"
) ;End command
 (command "ucs" "w" 
) ;End command
 (command "box" p1 p6 h
   "box" p4 p7 h
   "box" p2 p8 m
   "box" p13 p16 (- (+ m))
) ;End Command
 (command "zoom" "a"
) ;End Command

 ;End of Commands made by MR. CAD
 (setvar "osmode" 32)
 ;switch ON snap

 ;*
 ;Reset System Variable
 (setvar "osmode" oldsnap)
 ;Reset snap
 (setvar "blipmode" oldblipmode)
 ;Reset blipmode

 ;*
 (princ)
 ;finish cleanly

 ) ;end of defun
;*
;This function converts Degrees to Radians.
(defun dtr (x)
 ;define degrees to radians function
 (* pi (/ x 180.0))
 ;divide the angle by 180 then
 ;multiply the result by the constant PI
) ;End of function
;*
(princ) ;load cleanly
;*
;;HOPE THIS LISP WILL BE FUNCTIONAL FOR THE USER
;;MADE BY MR. CAD
;;END LISP

Link to comment
Share on other sites

Ok I made a bit improvement myself. I have actualle another question.. again...

 

(command "box" p1 p6 h
   "attdef" "" "Name" "Top" "" p1 "" ""
   "attdef" "" "Hight" h "" p1 "" ""
   "attdef" "" "Width" d "" p1 "" ""
   "attdef" "" "Thickness" m "" p1 "" ""

 

This command will create an box, with on the position of p1 the attributes as given.

The only command I have to insert now as for as I know is creating a block with theese objects... so.

Is there an command or an option to create automatic an block of these values?

If I could create a block of the box with attdef's I am close to my target...

 

Regards MR

Link to comment
Share on other sites

entmaking BLOCKs and INSERTs is a tedious deal.

 

Due to the fact your are dealing with a 3dsoild, you cannot make the entity dynamically. You must use a (entget) call

 

You will have to add the balance of ATTDEFs and ATTRIBs, but it's a start.

 

 

 (command "box" p1 p6 h)
;  (setq p1 '(10 10 0))
;  (command "_SOLID" '(10 10 0) '(20 10 0) '(10 20 0) '(20 20 0) "")
 (setq fe (entlast))

 (setq bc 1 bn "TEMP1")
 (while (tblsearch "BLOCK" bn)
        (setq bc (1+ bc) bn (strcat "TEMP" (itoa bc))))

 (entmake (list (cons 0 "BLOCK")(list 10 0 0 0)(cons 2 bn)(cons 70 2)))
 (entmake (entget fe))
 (entmake (list (cons 0 "ATTDEF")
                (cons 8 "0")
                (cons 10 '(0 0 0))
                (cons 11 '(0 0 0))
                (cons 40 1)
                (cons 1 (strcat "(" (rtos (car p1) 2  " "
                                    (rtos (cadr p1) 2  " "
                                    (rtos (caddr p1) 2  ")"))
                (cons 3 "TOP")
                (cons 2 "NAME")
                (cons 70 0)
                (cons 73 0)
                (cons 50 0)
                (cons 41 1)
                (cons 51 0)
                (cons 7 "STANDARD")
                (cons 71 0)
                (cons 72 0)
                (cons 210 (list 0 0 1))
                (cons 74 0)
                (cons 62 256)
                (cons 39 0)
                (cons 6 "BYLAYER")))
 (entmake (list (cons 0 "ENDBLK")(cons 8 "0")))

 (entdel fe)

 (entmake (list (cons 0 "INSERT")(cons 2 bn)(cons 10 '(0 0 0))(cons 66 1)
                (cons 62 256)
                (cons 39 0)
                (cons 6 "BYLAYER")))
 (entmake (list (cons 0 "ATTRIB")
                (cons 8 "0")
                (cons 10 '(0 0 0))
                (cons 11 '(0 0 0))
                (cons 40 1)
                (cons 1 (strcat "(" (rtos (car p1) 2  " "
                                    (rtos (cadr p1) 2  " "
                                    (rtos (caddr p1) 2  ")"))
                (cons 2 "NAME")
                (cons 70 0)
                (cons 73 0)
                (cons 50 0)
                (cons 41 1)
                (cons 51 0)
                (cons 7 "STANDARD")
                (cons 71 0)
                (cons 72 0)
                (cons 210 (list 0 0 1))
                (cons 73 0)
                (cons 62 256)
                (cons 39 0)
                (cons 6 "BYLAYER")))
 (entmake (list (cons 0 "SEQEND")(cons 8 "0")))


 

-David

Link to comment
Share on other sites

Hi All!

 

Well I notice that theire is not that much response on my question.

So I attach an attachment. maybe someone will understand right know...

 

You can see on my image that I set some references with the lisp I wil also attach as file and below.

 

Now it shows as value (1756 - 1626 0) I noticed That I could inculde a word by name but I can't remove the nummeric numbers...

Any response would be great

 

Regards MR

 

(defun c:kast ()
 ;MR. CAD - Mitchell Rodhouse
 ;Autocad The Netherlands 
 ;define the function
 ;*
 ;Save System Variables
 (setq oldsnap (getvar "osmode"))

 ;save snap settings
 (setq oldblipmode (getvar "blipmode"))
 ;save blipmode setting
 (setvar "cmdecho" 0)
 (setvar "INSUNITS" 4)
 ;*
 ;Switch OFF system Variables
 (setvar "osmode" 0)
 ;Switch OFF snap
 (setvar "blipmode" 0)
 ;Switch OFF Blipmode
 ;*

 ;get User Inputs
 ;get User Inputs
 (setq b (getdist "\nWidth of the cabinet : "))
 ;Width of the cabinet

 (setq h (getdist "\nHight of the cabinet : "))
 ;Hight of the cabinet
 (setq d (getdist "\nDepth of the cabinet : "))
 ;Depth of the cabinet
 (setq m (getdist "\nMaterialthickness of the cabinet : "))
 ;Materialthicknes of the cabinet
 ;*
 ;Get Insertion Point
 (setq ip (getpoint "\nInsertion Point : "))
 ;get the insertion point
 (setvar "osmode" 32)
 ;switch ON snap
 (setvar "osmode" 0)
 ;switch OFF snap
 ;*

 ;Start of Polar Calculations
 ;This are calculation made by MR Cad
 (setq p1 (polar ip (dtr 0.0) 0.0))
 (setq p2 (polar p1 (dtr 0.0) m))
 (setq p3 (polar p1 (dtr 0.0) b))
 (setq p4 (polar p3 (dtr 180.0) m))
 (setq p5 (polar p1 (dtr -90.0) d))
 (setq p6 (polar p5 (dtr 0.0) m))
 (setq p7 (polar p5 (dtr 0.0) b))
 (setq p8 (polar p7 (dtr 180.0) m))
 (setq p9 (list (car p1) (cadr p1) (+ (caddr p1) m)))
 (setq p10 (list (car p4) (cadr p4)(+ (caddr p4) m)))
 (setq p11 (polar p9 (dtr -90.0) d))
 (setq p12 (polar p10 (dtr -90.0) d))
 (setq p13 (list (car p2) (cadr p2) (+ (caddr p2) h)))
 (setq p14 (list (car p4) (cadr p4)(+ (caddr p4) h)))
 (setq p15 (polar p13 (dtr -90.0) d))
 (setq p16 (polar p14 (dtr -90.0) d))
 (setq p17 (list (car p13) (cadr p13) (- (caddr p13) m)))
 (setq p18 (list (car p14) (cadr p14) (- (caddr p14) m)))
 (setq p19 (list (car p15) (cadr p15) (- (caddr p15) m)))
 (setq p20 (list (car p16) (cadr p16) (- (caddr p16) m)))

 ;End of the Polar calculations by MR. CAD
 ;*
 ;Start Command Function
 (command "_-view" "_swiso"
) ;End command
 (command "ucs" "w" 
) ;End command

(command "box" p1 p6 h)
;  (setq p1 '(10 10 0))
;  (command "_SOLID" '(10 10 0) '(20 10 0) '(10 20 0) '(20 20 0) "")
 (setq fe (entlast))
 (setq bc 1 bn "Leftside1")
 (while (tblsearch "BLOCK" bn)
        (setq bc (1+ bc) bn (strcat "Leftside" (itoa bc))))
 (entmake (list (cons 0 "BLOCK")(list 10 0 0 0)(cons 2 bn)(cons 70 2)))
 (entmake (entget fe))
;*********************************************************************************
 (entmake (list (cons 0 "ATTDEF")
                (cons 8 "0")
                (cons 10 '(0 0 0))
                (cons 11 '(0 0 0))
                (cons 40 1)
                (cons 1 (strcat "(" (rtos (car p1) 2 0) "Leftside"
                                    (rtos (cadr p1) 2 0) " "
                                    (rtos (caddr p1) 2 0) ")"))
                (cons 3 "Leftside")
                (cons 2 "Name:")
                (cons 70 0)
                (cons 73 0)
                (cons 50 0)
                (cons 41 1)
                (cons 51 0)
                (cons 7 "STANDARD")
                (cons 71 0)
                (cons 72 0)
                (cons 210 (list 0 0 1))
                (cons 74 0)
                (cons 62 256)
                (cons 39 0)
                (cons 6 "BYLAYER")))
;*********************************************************************************
   (entmake (list (cons 0 "ATTDEF")
                (cons 8 "0")
                (cons 10 '(0 0 0))
                (cons 11 '(0 0 0))
                (cons 40 1)
                (cons 1 (strcat "(" (rtos (car p1) 2 0) " "
                                    (rtos (cadr p1) 2 0) " "
                                    (rtos (caddr p1) 2 0) ")"))
                (cons 3 "Hight1")
                (cons 2 "Hight")
                (cons 70 0)
                (cons 73 0)
                (cons 50 0)
                (cons 41 1)
                (cons 51 0)
                (cons 7 "STANDARD")
                (cons 71 0)
                (cons 72 0)
                (cons 210 (list 0 0 1))
                (cons 74 0)
                (cons 62 256)
                (cons 39 0)
                (cons 6 "BYLAYER")))
;*********************************************************************************
  (entmake (list (cons 0 "ATTDEF")
                (cons 8 "0")
                (cons 10 '(0 0 0))
                (cons 11 '(0 0 0))
                (cons 40 1)
                (cons 1 (strcat "(" (rtos (car p1) 2 0) " "
                                    (rtos (cadr p1) 2 0) " "
                                    (rtos (caddr p1) 2 0) ")"))
                (cons 3 "Widht1")
                (cons 2 "Widht")
                (cons 70 0)
                (cons 73 0)
                (cons 50 0)
                (cons 41 1)
                (cons 51 0)
                (cons 7 "STANDARD")
                (cons 71 0)
                (cons 72 0)
                (cons 210 (list 0 0 1))
                (cons 74 0)
                (cons 62 256)
                (cons 39 0)
                (cons 6 "BYLAYER")))
;*********************************************************************************
  (entmake (list (cons 0 "ATTDEF")
                (cons 8 "0")
                (cons 10 '(0 0 0))
                (cons 11 '(0 0 0))
                (cons 40 1)
                (cons 1 (strcat "(" (rtos (car p1) 2 0) " "
                                    (rtos (cadr p1) 2 0) " "
                                    (rtos (caddr p1) 2 0) ")"))
                (cons 3 "Thickness1")
                (cons 2 "Thickness")
                (cons 70 0)
                (cons 73 0)
                (cons 50 0)
                (cons 41 1)
                (cons 51 0)
                (cons 7 "STANDARD")
                (cons 71 0)
                (cons 72 0)
                (cons 210 (list 0 0 1))
                (cons 74 0)
                (cons 62 256)
                (cons 39 0)
                (cons 6 "BYLAYER")))
;*********************************************************************************
 (entmake (list (cons 0 "ENDBLK")(cons 8 "0")))
 (entdel fe)
 (entmake (list (cons 0 "INSERT")(cons 2 bn)(cons 10 '(0 0 0))(cons 66 1)
                (cons 62 256)
                (cons 39 0)
                (cons 6 "BYLAYER")))
;*********************************************************************************
 (entmake (list (cons 0 "ATTRIB")
                (cons 8 "0")
                (cons 10 '(0 0 0))
                (cons 11 '(0 0 0))
                (cons 40 1)
                (cons 1 (strcat "(" (rtos (car p1) 2 0) "Leftside"
                                    (rtos (cadr p1) 2 0) " "
                                    (rtos (caddr p1) 2 0) ")"))
                (cons 2 "Name:")
                (cons 70 0)
                (cons 73 0)
                (cons 50 0)
                (cons 41 1)
                (cons 51 0)
                (cons 7 "STANDARD")
                (cons 71 0)
                (cons 72 0)
                (cons 210 (list 0 0 1))
                (cons 73 0)
                (cons 62 256)
                (cons 39 0)
                (cons 6 "BYLAYER")))
;*********************************************************************************  
 (entmake (list (cons 0 "ATTRIB")
                (cons 8 "0")
                (cons 10 '(0 0 0))
                (cons 11 '(0 0 0))
                (cons 40 1)
                (cons 1 (strcat "(" (rtos (car p1) 2 0) " "
                                    (rtos (cadr p1) 2 0) " "
                                    (rtos (caddr p1) 2 0) ")"))
                (cons 2 "Hight")
                (cons 70 0)
                (cons 73 0)
                (cons 50 0)
                (cons 41 1)
                (cons 51 0)
                (cons 7 "STANDARD")
                (cons 71 0)
                (cons 72 0)
                (cons 210 (list 0 0 1))
                (cons 73 0)
                (cons 62 256)
                (cons 39 0)
                (cons 6 "BYLAYER")))
 ;*********************************************************************************
 (entmake (list (cons 0 "ATTRIB")
                (cons 8 "0")
                (cons 10 '(0 0 0))
                (cons 11 '(0 0 0))
                (cons 40 1)
                (cons 1 (strcat "(" (rtos (car p1) 2 0) " "
                                    (rtos (cadr p1) 2 0) " "
                                    (rtos (caddr p1) 2 0) ")"))
                (cons 2 "Widht")
                (cons 70 0)
                (cons 73 0)
                (cons 50 0)
                (cons 41 1)
                (cons 51 0)
                (cons 7 "STANDARD")
                (cons 71 0)
                (cons 72 0)
                (cons 210 (list 0 0 1))
                (cons 73 0)
                (cons 62 256)
                (cons 39 0)
                (cons 6 "BYLAYER")))
;*********************************************************************************
  (entmake (list (cons 0 "ATTRIB")
                (cons 8 "0")
                (cons 10 '(0 0 0))
                (cons 11 '(0 0 0))
                (cons 40 1)
                (cons 1 (strcat "(" (rtos (car p1) 2 0) " "
                                    (rtos (cadr p1) 2 0) " "
                                    (rtos (caddr p1) 2 0) ")"))
                (cons 2 "Thickness")
                (cons 70 0)
                (cons 73 0)
                (cons 50 0)
                (cons 41 1)
                (cons 51 0)
                (cons 7 "STANDARD")
                (cons 71 0)
                (cons 72 0)
                (cons 210 (list 0 0 1))
                (cons 73 0)
                (cons 62 256)
                (cons 39 0)
                (cons 6 "BYLAYER")))
 ;*********************************************************************************


 (entmake (list (cons 0 "SEQEND")(cons 8 "0"))

) ;End Command

 (command "zoom" "a"
) ;End Command

 ;End of Commands made by MR. CAD
 (setvar "osmode" 32)
 ;switch ON snap

 ;*
 ;Reset System Variable
 (setvar "osmode" oldsnap)
 ;Reset snap
 (setvar "blipmode" oldblipmode)
 ;Reset blipmode

 ;*
 (princ)
 ;finish cleanly

 ) ;end of defun
;*
;This function converts Degrees to Radians.
(defun dtr (x)
 ;define degrees to radians function
 (* pi (/ x 180.0))
 ;divide the angle by 180 then
 ;multiply the result by the constant PI
) ;End of function
;*
(princ) ;load cleanly
;*
;;HOPE THIS LISP WILL BE FUNCTIONAL FOR THE USER
;;MADE BY MR. CAD
;;END LISP

block.jpg

kast2.LSP

Link to comment
Share on other sites

You need to change the values for group 1 to your values

 

For the height:

 

(cons 1 (rtos h 2))

or

(cons 1 (strcat "Height = " (rtos h 2)))

 

You need to look into DIMZIN and LUPREC settings to control leading and trailing zeros.

 

-David

Link to comment
Share on other sites

you are a genius!:D

now I alread made it work for one box.. stil have to try get it work for the other boxes, do you hav a tip how I sould set it up? because If I ad an box command under the other box it stays an solid logical... but if I (princ) under theese code I can't start this al again am I right>?

 

Regards MR

Link to comment
Share on other sites

(cons 1 (rtos b 2)) can I also give this value of "b" but than minus 2xm? my material thickness is m so the length is b-m-m can it be done?

 

I made : (cons 1 (rtos d (- (+ m m)) 2))

but that isn't working xD

Regards MR

Link to comment
Share on other sites

(cons 1 (rtos b 2)) can I also give this value of "b" but than minus 2xm? my material thickness is m so the length is b-m-m can it be done?

 

I made : (cons 1 (rtos d (- (+ m m)) 2))

but that isn't working xD

Regards MR

 

(rtos (- b m m) 2)
or
(rtos (- b (* m 2)) 2)

Link to comment
Share on other sites

you are a genius!:D

now I alread made it work for one box.. stil have to try get it work for the other boxes, do you hav a tip how I sould set it up? because If I ad an box command under the other box it stays an solid logical... but if I (princ) under theese code I can't start this al again am I right>?

 

Regards MR

 

 

You must save each boxes ename as they are made

(command "box" .....)
(setq fe (entlast))  ;;;first entity

(command "box" .....)
(setq se (entlast))  ;;;second entity

(command "box" .....)
(setq te (entlast))  ;;;third entity

 

and then entmake the entity definition in the block table definition

(entmake (entget fe))
(entmake (entget se))
(entmake (entget te))

and then delete the original entity

 

(entdel fe)
(entdel se)
(entdel te)

-David

Link to comment
Share on other sites

Well David it works all; drawing the romp of a cabinet in 3d and adding the attributes for a later converting to excel.

I can only say thank you! I'll post it for other users below and for people who wants to make improvements on this lisp;

 

Regards MR

Cabinet.LSP

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...