Jump to content

Lisp to insert text cod according to data base


wrha

Recommended Posts

I have data base for objects i need lisp when I write code of the object insert

Description as text in autocad

 

Example

 

description Code

 

M20 socket M20

M24 socket M24

M30 socket M30

 

What i mean when I write M20 lisp insert M20 socket.

Link to comment
Share on other sites

It is just a matter of asking the user to specify a point and the text is inserted !

Is not the right time to try your own abilities to write this simple lisp ?

Link to comment
Share on other sites

You must be lazy :) so have a play with this and let me know .

 

(defun c:Test (/ kw st pt)
 ;; Tharwat 24.08.2015    ;;
 (if
   (and (progn
          (initget 6 "20 24 30")
          (setq kw
                 (getkword
                   "\nSpecify the insertion text key < M(**) socket M(**) > [20,24,30] <Enter = Exit>:"
                 )
          )
        )
        (setq
          st (nth (vl-position kw '("20" "24" "30"))
                  '("M20 socket M20" "M24 socket M24" "M30 socket M30")
             )
        )
   )
    (while (setq pt
                  (getpoint
                    (strcat "\nSpecify insertion point for text < "
                            st
                            " > <Enter = Exit>:"
                    )
                  )
           )
      (entmake (list '(0 . "TEXT")
                     (cons 10 (trans pt 1 0))
                     (cons 11 (trans pt 1 0))
                     (cons 1 st)
                     (cons 7 (getvar 'TEXTSTYLE))
                     (cons 40 (getvar 'TEXTSIZE))
               )
      )
    )
 )
 (princ)
)

Link to comment
Share on other sites

I Try To add M40 to insert socket 40

Have a close look .

 

(and (progn
          (initget 6 "20 24 30 [color=magenta]40[/color]")
          (setq kw
                 (getkword
                   "\nSpecify the insertion text key < M(**) socket M(**) > [20,24,30,[color=magenta]40[/color]] <Enter = Exit>:"
                 )
          )
        )
        (setq
          st (nth (vl-position kw '("20" "24" "30" [color=magenta]"40"[/color]))
                  '("M20 socket M20" "M24 socket M24" "M30 socket M30" [color=magenta]"M40 socket M40"[/color])
             )
        )
   )

Link to comment
Share on other sites

Here's another approach, to remove an extra step:

(   (lambda nil
       (foreach x '("20" "24" "30" "40")
           (eval
               (list 'defun  (read (strcat "c:m" x)) '( / ins ocs )
                  '(setq ocs (trans '(0 0 1) 1 0 t))
                   (list 'if '(setq ins (getpoint "\nSpecify point for text: "))
                       (list 'entmake
                           (list 'list
                             ''(0 . "TEXT")
                              '(cons 10 (trans ins 1 ocs))
                              '(cons 11 (trans ins 1 ocs))
                              '(cons 40 (getvar 'textsize))
                              '(cons 07 (getvar 'textstyle))
                              '(cons 50 (angle '(0.0 0.0) (trans (getvar 'ucsxdir) 0 ocs t)))
                               (list 'quote (cons 1 (strcat "M" x " Socket")))
                             ''(72 . 1)
                             ''(73 . 2)
                              '(cons 210 ocs)
                           )
                       )
                   )
                  '(princ)
               )
           )
       )
   )
)

The above will define the custom commands: 'M20', 'M24', 'M30', 'M40'.

Link to comment
Share on other sites

A couple more suggestions.

 

If your doing this over and over you could just type M20 with a series of little lisp defuns in one lsip file, (defun c:M20 () ......

 

Why not even a menu item "Bolts" 20 30 40 etc or a toolbar.

 

A DCL list select.

 

If I can get the old screen menu working another way.

 

There are a lot of choices. Have a go at doing one of the others yourself.

Link to comment
Share on other sites

I ALREADY I DID BUT KINDLY TO CHECK WHATS PROPLEM IN M30 , M36 OTHERS WORKING OK .

 

(defun c:socket (/ kw st pt)

;; Tharwat 24.08.2015 ;;

(if

(and (progn

(initget 16 "M12 M16 M20 M24 M30 M36")

(setq kw

(getkword

"\nSpecify the insertion text key [12,16,20,30,36] :"

)

)

)

(setq

st (nth (vl-position kw '("M12" "M16" "M20" "30" "36"))

'("M12 810220 pcs" "M16 810221 pcs" "M20 810222 pcs" "M24 810223 pcs" "M24 810224 pcs" "M36 810225 pcs")

)

)

)

(while (setq pt

(getpoint

(strcat "\nSpecify insertion point for text

st

" > :"

)

)

)

(entmake (list '(0 . "TEXT")

(cons 10 (trans pt 1 0))

(cons 11 (trans pt 1 0))

(cons 1 st)

(cons 7 (getvar 'TEXTSTYLE))

(cons 40 (getvar 'TEXTSIZE))

)

)

)

)

(princ)

)

Link to comment
Share on other sites

add my data base and its huge
Just me I would setup a text file with all the data, even different ones, this would be easier than bloating the lisp file. You could have a shortcut for each type but run only 1 master file. Bolts, Bolts and length etc.
Link to comment
Share on other sites

I ALREADY I DID BUT KINDLY TO CHECK WHATS PROPLEM IN M30 , M36 OTHERS WORKING OK .

 

 (vl-position kw '("M12" "M16" "M20" "30" "36")

 

Is the above list the same as the one that I included in my program ?

Link to comment
Share on other sites

kindly to refer by different color for input and output to got possibility to add my data base because for each object (socket) I have code number .

for example when I select

(M20)insert (812020)

(M24)insert (812024) ... etc

the objects which I need to add it is to much .

I hope I got help

thanks

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