Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Mtext or Diesel expression Solution??

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Anonymous
1540 Views, 5 Replies

Mtext or Diesel expression Solution??

Hi Guys,

 

I've previousdly poseted this in the AutoCAD 2010 area but now i'm going t otry my luck here!!

 

 

We're looking for a way to list a layout tab in mtext, ideally what we would like to achieve is an mtext string that will pick up the preceeding or suceeding layout tab name.

 

What we're trying to achieve is an mtext that will automatically pick these up as we use mtext to say

 

"Joins Drg. [project number] [previous layout name]"

 

"Joins Drg. [project number] [suceeding layout name]"

 

Could this be achieved by adding or subtracting from the current layout tab name which we usually have a number??

 

Since my orignal post i've come up with the diesel expression in the attachemnt but it won't include 000's in front of a layout name, we generally use 4 digit layout names so this is a problem. I've included 4 random layout names in the file attached.

 

Let me know wat you guys think.

 

Regards,

B

 

 

Thanks,

 

B

5 REPLIES 5
Message 2 of 6
scottbolton
in reply to: Anonymous

Drummerboy,

 

This is a bit rough 'n' ready but it gets you there:

 

(setq XD_layoutlist nil)
;;; get all the layout names ;;
(vlax-for XD_layout (vla-get-layouts (vla-get-activeDocument (vlax-get-acad-object)))
  (setq XD_layoutlist (cons (vla-get-Name XD_layout) XD_layoutlist))
  )
;;; get the active layout name and deduce the previous and following ones ;;;
(setq XD_layoutname (vla-get-Name (vla-get-ActiveLayout (vla-get-activeDocument (vlax-get-acad-object))))
      XD_layoutnum (atoi XD_layoutname)
      XD_prev (itoa (1- XD_layoutnum))
      XD_next (itoa (1+ XD_layoutnum))
      )
;;; ensure they are 4 characters long ;;
(while (< (strlen XD_prev) 4) (setq XD_prev (strcat "0" XD_prev)))
(while (< (strlen XD_next) 4) (setq XD_next (strcat "0" XD_next)))
;;; check if they exist ;;
(if (member XD_prev XD_layoutlist) (setq XD_prevtext (strcat "Joins Drg. [project number] [" XD_prev "]")))
(if (member XD_next XD_layoutlist) (setq XD_nexttext (strcat "Joins Drg. [project number] [" XD_next "]")))

 

S

Message 3 of 6
Anonymous
in reply to: scottbolton

I know nothing about lisp or programming so if this is a lisp what command to in envoke to run it??

 

Thanks,

 

B

Message 4 of 6
scottbolton
in reply to: Anonymous

Ok, save this code to SBLO.lsp anywhere on your network.

 

(defun c:SBLO ( / XD_layoutlist XD_layoutname XD_layoutnum XD_prev XD_next XD_prevtext XD_nexttext)
  ;;; get all the layout names ;;
  (vlax-for XD_layout (vla-get-layouts (vla-get-activeDocument (vlax-get-acad-object)))
    (setq XD_layoutlist (cons (vla-get-Name XD_layout) XD_layoutlist))
    )
  ;;; get the active layout name and deduce the previous and following ones ;;;
  (setq XD_layoutname (vla-get-Name (vla-get-ActiveLayout (vla-get-activeDocument (vlax-get-acad-object))))
 XD_layoutnum (atoi XD_layoutname)
 XD_prev (itoa (1- XD_layoutnum))
 XD_next (itoa (1+ XD_layoutnum))
 )
  ;;; ensure they are 4 characters long ;;
  (while (< (strlen XD_prev) 4) (setq XD_prev (strcat "0" XD_prev)))
  (while (< (strlen XD_next) 4) (setq XD_next (strcat "0" XD_next)))
  ;;; check if they exist ;;
  (if (member XD_prev XD_layoutlist) (setq XD_prevtext (strcat "Joins Drg. [project number] [" XD_prev "]")))
  (if (member XD_next XD_layoutlist) (setq XD_nexttext (strcat "Joins Drg. [project number] [" XD_next "]")))
  ;;; get the insertion points of the text ;;
  (if (setq XD_pt1 (getpoint "\nPick the insert point for the 'previous' text: "))
    (progn
      (if (setq XD_pt2 (getpoint "\nPick the insert point for the 'following' text: "))
 (progn
   (command "_MTEXT" XD_pt1 "_J" "_MC" XD_pt1 XD_prevtext "")
   (command "_MTEXT" XD_pt2 "_J" "_MC" XD_pt2 XD_nexttext "")
   )
 (princ "\nCancelled by user\n")
 )
      )
    (princ "\nCancelled by user\n")
    )
  (princ)
  )
(princ "\nType SBLO to run...\n")

 

In AutoCAD, type APPLOAD and browse to the file. Now type SBLO to run it.

 

To edit the file you'd better use the VLISP console - type VLIDE in AutoCAD.

 

There's no error checking in there so if you're in modelspace you'll get dodgy results - check for the layout name (XD_layoutname) and/or the system variable CVPORT (getvar "CVPORT"). You'll also need to set the project number - either "hard-wire" it in the file itself (not very useful) of ask the user for it - look up "getstring" in the VLIDE help file.

 

Lots of stuff to whet your appetite. Have a bash and come back with what you've got.

 

S

Message 5 of 6
Anonymous
in reply to: Anonymous

You can try these two Diesel-Expressions:

 

$(if,$(=,$(strlen,$(-,$(rtos,$(substr,$(getvar,ctab),1,4)),1)),1),000,
$(if,$(=,$(strlen,$(-,$(rtos,$(substr,$(getvar,ctab),1,4)),1)),2),00,
$(if,$(=,$(strlen,$(-,$(rtos,$(substr,$(getvar,ctab),1,4)),1)),3),0)))
$(-,$(rtos,$(substr,$(getvar,ctab),1,4)),1)

 

and

 

$(if,$(=,$(strlen,$(+,$(rtos,$(substr,$(getvar,ctab),1,4)),1)),1),000,
$(if,$(=,$(strlen,$(+,$(rtos,$(substr,$(getvar,ctab),1,4)),1)),2),00,
$(if,$(=,$(strlen,$(+,$(rtos,$(substr,$(getvar,ctab),1,4)),1)),3),0)))
$(+,$(rtos,$(substr,$(getvar,ctab),1,4)),1)

 

You should remove the line feeds, should be all in one line.

Message 6 of 6
Anonymous
in reply to: Anonymous

Excellent work Stephan!!

 

I just forwarded it on for evaluation by our team but it looks good to me!!

 

Thanks,

 

B

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost