Jump to content

Help to fix Align text lisp


mhy3sx

Recommended Posts

Hi. I use this code to align text, mtext on the right side of a vertical line. This code works fine in AutoCad. I am using Zwcad now and this code not work properly.

 

Start with select line , and then select text and then stop don't move the text,mtext to the correct position. The strange thing is that Zwcad don't gives me any error message.

 

This is the code

 

(defun c:FOO (/ col int sel int ent get grp vla ins)
(vl-load-com)
  (and (setq col (car (entsel "\n Select Line :")))
   (or (= (cdr (assoc 0 (entget col))) "LINE")
   (alert "Try again !!!")
   )
   (princ "\nSelect TEXT,MTEXT")
   (setq int -1 sel (ssget "_:L" '((0 . "*TEXT"))))
   (while (setq int (1+ int) ent (ssname sel int))
 (and (setq get (entget ent))
  (or (and (= (cdr (assoc 0 get)) "TEXT")
   (setq grp '((71 . 0) (72 . 2) (73 . 0)))
   )
  (setq grp '((71 . 3) (72 . 5) (73 . 1)))
  )
  (entmod (append (entmod (subst (cons 11 (cdr (assoc 10 get))) (assoc 11 get) get)) grp))
  (or (vla-getboundingbox (setq vla (vlax-ename->vla-object ent)) 'lft 'rgt)
  (setq ins (vlax-safearray->list rgt))
  )
  (vlax-invoke vla 'Move ins (vlax-curve-getclosestpointto col ins))
  )
 )
   )
  (princ)
) 
 

 

Any Ideas why ?

 

Thanks

 

Link to comment
Share on other sites

Its probably the vla commands that are causing the issue. either contact zcad or try to find documentation online of what lisp functions are acceptable.

 

like here is what can be used in Solidworks.

Link to comment
Share on other sites

Hi Tharwat . I find this code in a post but I don't remember the site or the link. I use it over a year now.

Edited by mhy3sx
Link to comment
Share on other sites

It is often useful to make a note where you found a routine - every now and then they get updated on the forums, people find the thread and might have asked the same there.... so it is good to go and look but also good to recognise the author. The style of LISP above are similar to a couple of posters on here, they might come and take the credit...

 

I use AutoCAD...so the above works but as far as I know the problems can be caused by vla- and vlax- functions, they arn't all supported.

 

This might work, it might not, taking out the VLA- and VLAX- commands. Uses Lee Macs ProjectPointToLine (see his website for use).

 

I've tried to annotate it so as it runs it will return in the command line what it is doing, what it has calculated and found - if anything there is nil and the routine doesn't work then ZWCad probably doesn't support that (or I have got it wrong).

 

 

(defun c:Foo ( / col sel int old get inspt pt p1 p2)
  (defun LM:ProjectPointToLine ( pt p1 p2 / nm ) ;Find nearest point on line (p1-p2) to point (pt)
    (setq nm (mapcar '- p2 p1)
          p1 (trans p1 0 nm)
          pt (trans pt 0 nm)
    )
    (trans (list (car p1) (cadr p1) (caddr pt)) nm 0)
  )

  (while (/= (cdr (assoc 0 (entget (setq col (car (entsel "\nSelect a Line")))))) "LINE" )
    (Princ "Missed, Try again!")
  ) ; end while
  (setq pt1 (cdr (assoc 10 (entget col))))   ;;line end point A
  (setq pt2 (cdr (assoc 11 (entget col))))   ;;line end point B
  (princ "\nLine Selected, Entity name: ")(princ col)
  (princ ". End A: ")(princ pt1)(princ ". End B: ")(princ pt2)

  (princ "\nSelect Text or Mtext: ")
  (setq sel (ssget "_:L" '((0 . "*TEXT"))))  ;;text or Mtext
  (princ "\n")(princ (sslength sel))(princ " texts selected")

  (setq int 0)
  (while (< int (sslength sel))
    (princ "\nWhile Loop iteration ")(princ (+ int 1))(princ "\n")
    (setq ent (ssname sel int))
    (setq old (getvar 'nomutt))(setvar 'nomutt 1)
    (command "_.justifytext" ent "" "tr")
    (setvar 'nomutt old)
    (princ ". Text Justified to 'TR'")
    (setq get (entget ent))
    (setq inspt (cons 10 (LM:ProjectPointToLine (cdr (assoc 10 get)) p1 p2) ))
    (princ "\nNew Insertion Point: ")(princ inspt)
    (setq get (subst inspt (assoc 10 get) get))
    (entmod get)(entupd ent)
    (setq int (+ int 1))
  ) ; end while

  (princ) ; exit silently
)

 

 

For a quick routine it just looks at the closest points to a line, for more versatility it would be nice to do the same (without VLA- functions) for all entity types... but that is for another time.. just taking a break tonight from another (much larger) project update.

 

 

Edited by Steven P
  • Like 1
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...