Jump to content

Hi,help to make function


Recommended Posts

Hello guys

I have got following code for insert mtext in my drawing

 

 (defun c:MyMtext (/ pt1 pt2 txt)
  (setq pt1  (getpoint "\nSelect top left corner: ")
        pt2  (getcorner pt1 "\nSelect bottom rigth corner: ")
	TXT   "LOVE YOU"
  )
   (command "_.mtext" pt1 pt2 txt "")
  (princ)
)

 i like and try change it to function something like following ::

 (defun MyMtext ( pt1 pt2 txt)
  (setq pt1  (getpoint "\nSelect top left corner: ")
        pt2  (getcorner pt1 "\nSelect bottom rigth corner: ")
  )
   (command "_.mtext" pt1 pt2 txt "")
  (princ)
)

and use it by::

(MyMtext (txt))

but when i use above function code , receipted the error.anyone cold correct me please ,i would be appropriated in advance

Edited by hosyn
Link to post
Share on other sites
tombu

Try

 (defun MyMtext ( txt / pt1 pt2)
  (setq pt1  (getpoint "\nSelect top left corner: ")
        pt2  (getcorner pt1 "\nSelect bottom rigth corner: ")
  )
   (command "_.mtext" pt1 pt2 txt "")
  (princ)
)

and use it by:

(MyMtext "LOVE YOU")

 

Link to post
Share on other sites
BIGAL

You can go way more advanced and using entmake is super fast. The lr and lor control alignment can be left out.

 

(defun AH:text (pt hgt str ang lr lor )
(entmake
	(list
		(cons 0 "MTEXT")
		(cons 100 "AcDbEntity")
		(cons 100 "AcDbMText")
		(cons 8 layer)
		(cons 42 1) 
		(cons 43 0) 
		(cons 44 1) 
		(cons 7 "Standard")
		(cons 1 str)
		(cons 10 pt)
 		(cons 11 (list 0.0 0.0 0.0))
		(cons 210 (list 0.0 0.0 1.0))
		(cons 40 hgt)
		(cons 50 ang)
		(cons 71 lr)
		(cons 72 lor)
	)
)
)

 

Link to post
Share on other sites

and what would be wrong in the following function when the primary code didnt have any ERRORS

  (defun list-pt ( pt1 pt2 ) ;;
(setq cntr 1)
(while (<= cntr 3 )		
        (if (= cntr 1)
            (setq pag-lis-hos (list pt1 pt2))
	    (setq pag-lis-hos (list pag-lis-hos (list pt1 pt2))))
  (setq cntr (+ 1 cntr))
)	      
  )
              
              
  (list-pt  ((-1519.44 -294.077 0.0) (-1647.41 -415.598 0.0)) ) 
              ;or
   (list-pt  (-1519.44 -294.077 0.0) (-1647.41 -415.598 0.0) )             

 

Edited by hosyn
Link to post
Share on other sites

Not sure what you're trying to do but try this

(defun list-pt ( pt1 pt2 /)
  (setq pag-lis-hos (list pt1 pt2))
  (repeat 2 (setq pag-lis-hos (list pag-lis-hos (list pt1 pt2))))
)

Then enter 

(list-pt  "-1519.44,-294.077,0.0" "-1647.41,-415.598,0.0")

returns ((("-1519.44,-294.077,0.0" "-1647.41,-415.598,0.0") ("-1519.44,-294.077,0.0" "-1647.41,-415.598,0.0")) ("-1519.44,-294.077,0.0" "-1647.41,-415.598,0.0"))

Link to post
Share on other sites

Dear tombo

i wrote this code for saving list of some view rectangle between pt1,pt2 by following and append blank new view to list with name pag-lis-hos ::

  (defun c:test3 ( )
(setq nn (getint "No of views"));; nn is define by user	
(setq cntr 1) ;; define counter
(while (<= cntr nn ) ;; nn is define by user		
		(setq pt1(getpoint))
		(setq pt2(getpoint))

            (if (= cntr 1)
            (setq pag-lis-hos (list pt1 pt2)) ;;do for first time
	        (setq pag-lis-hos (list pag-lis-hos (list pt1 pt2)));;do for second and more
            ) ;;;;; pag-lis-hos total view points list
  )	      
  )

the above code work perfect and I gonna change it to function as ::

  (defun list-pt ( pt1 pt2 ) ;;; input pt1 pt2 output pag-lis-hos ((pt1 pt2) (pt1 pt2) (pt1 pt2) .....)
(setq cntr 1)
(setq nn (getint "No of views"));; nn is define by user
(while (<= cntr nn )		

            (if (= cntr 1)
            (setq pag-lis-hos (list pt1 pt2))
	        (setq pag-lis-hos (list pag-lis-hos (list pt1 pt2))))
  (setq cntr (+ 1 cntr))
  )	      
  )
 

the function is correct apperantly , but when i gonna recall function in my master program i had error, how can recall it without problem 

 (list-pt  "1.0,0.0,0.0" "2.0,1.0,0.0" )
or ....
in master proram as you see we getting pt1 and pt2 by user as
(setq pt1(getpoint))
(setq pt2(getpoint))
and we have pt1 and pt2 for each view we wanna by call the function append blank new view to list with name pag-lis-hos  

I hope i could clear my request

Edited by hosyn
Link to post
Share on other sites

Using quoted lists as arguments and using append should fix all those issues

Changing list to use append in my previous post

(defun list-pt ( pt1 pt2 /)
  (setq pag-lis-hos (list(list pt1 pt2)))
  (repeat 2 (setq pag-lis-hos (append pag-lis-hos (list(list pt1 pt2)))))
)

Using quoted lists as arguments

(list-pt  '(-1519.44 -294.077 0.0) '(-1647.41 -415.598 0.0))

returns a list of paired points

(((-1519.44 -294.077 0.0) (-1647.41 -415.598 0.0)) ((-1519.44 -294.077 0.0) (-1647.41 -415.598 0.0)) ((-1519.44 -294.077 0.0) (-1647.41 -415.598 0.0)))
instead of 

((((-1519.44 -294.077 0.0) (-1647.41 -415.598 0.0)) ((-1519.44 -294.077 0.0) (-1647.41 -415.598 0.0))) ((-1519.44 -294.077 0.0) (-1647.41 -415.598 0.0)))
which makes referencing them difficult.

Link to post
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
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...