Author Topic: Select text obj, Place Multileaderstyle with attribute block from selected text.  (Read 2197 times)

0 Members and 1 Guest are viewing this topic.

jodeknudt

  • Mosquito
  • Posts: 5
Hello,
 
i've been working on a command where I:

  • Select a text or mtext object ;Done
  • Pick an arrow point and landing point for the MLeader ;Done
  • use those attributes to put in a multileader style with the the current multileader style.
It's the standard library "_tagslot" block with the "TAGNUMBER" attribute.
the code works great until the Edit Attributes window shows up and asks me to insert the value wich should be "txt" value from the code.

It is similar to MT2ML but I don't want the edit Attribute to prompt me.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:2ml ( / txt arp lap)
  2.         (vl-load-com)
  3.         (setq txt (vla-get-TextString(vlax-ename->vla-object (car (entsel))))) ;;; select content from text object
  4.        
  5.         (setq arp (getpoint "\nPick Arrow Location: "))
  6.         (setq lap (getpoint "\nPick Text Location: "))
  7.         (vl-cmdf "_mleader" arp lap txt "") ;;; This asks me for a prompt, wich is bad VERY BAD!
  8.        
  9. )

I have already prepared the dwg for you (acad 2010) with the custom multileader "blusapparaten"


EDIT: Some steps user-script relation.
The user only needs to click the text. (script Fetching the values)
The user sets the arrow and landing point.
Script does the rest. (putting in the values)

It's ment to quickly replace multiple text values wich represent extinguishers into custom style multileaders. where the user visually puts in the arrow (position of extinguisher) and the label (ie. avoid overlap of roomnumbers from xrefs)
« Last Edit: April 26, 2020, 05:32:37 AM by jodeknudt »

Dlanor

  • Bull Frog
  • Posts: 263
Here you go.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:2ml ( / sv_lst sv_vals txt arp lap)
  2.   (setq sv_lst (list 'cmleaderstyle 'clayer 'attreq)
  3.         sv_vals (mapcar 'getvar sv_lst)
  4.         txt (vlax-get (vlax-ename->vla-object (car (entsel))) 'textstring) ;;; select content from text object
  5.         arp (getpoint "\nPick Arrow Location: ")
  6.         lap (getpoint "\nPick Text Location: ")
  7.   );end_setq
  8.   (mapcar 'setvar sv_lst (list "BLUSAPPARAAT" "BLUSAPPARATEN" 1))
  9.   (vl-cmdf "_mleader" arp lap txt)
  10.   (mapcar 'setvar sv_lst sv_vals)
  11.   (princ)
  12. )
  13.  
« Last Edit: April 26, 2020, 09:02:41 AM by Dlanor »

jodeknudt

  • Mosquito
  • Posts: 5
I'm sorry, but the code still asks me to enter the value manually.

The user only needs to click the text. (script Fetching the values)
The user sets the arrow and landing point.
Script does the rest. (putting in the values)

It's ment to quickly replace multiple text values wich represent extinguishers into custom style multileaders. where the user visually puts in the arrow (position of extinguisher) and the label (ie. avoid overlap of roomnumbers from xrefs)

Here you go.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:2ml ( / sv_lst sv_vals txt arp lap)
  2.   (setq sv_lst (list 'cmleaderstyle 'clayer)
  3.         sv_vals (mapcar 'getvar sv_lst)
  4.         txt (vlax-get (vlax-ename->vla-object (car (entsel))) 'textstring) ;;; select content from text object
  5.         arp (getpoint "\nPick Arrow Location: ")
  6.         lap (getpoint "\nPick Text Location: ")
  7.   );end_setq
  8.   (mapcar 'setvar sv_lst (list "BLUSAPPARAAT" "BLUSAPPARATEN"))
  9.   (vl-cmdf "_mleader" arp lap txt "")
  10.   (mapcar 'setvar sv_lst sv_vals)
  11.   (princ)
  12. )
  13.  

Dlanor

  • Bull Frog
  • Posts: 263
I have amended the code in my initial post to try and account for a different system variable setup. Is this any better?

This as previously has been tested on your sample drawing.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
@jodeknudt, @Dlanor, do you use the same CAD? For example there is some difference between AutoCAD and BricsCAD with Mleader command...

jodeknudt

  • Mosquito
  • Posts: 5
@jodeknudt, @Dlanor, do you use the same CAD? For example there is some difference between AutoCAD and BricsCAD with Mleader command...

I'm using Autodesk AutoCAD 2017. Perhaps the problem lies on line 10?

There is a mleaderstyle used with a block as content. It always asks me to edit the attribute. here is the screenshot.



I know by looking on the commandline in Acad that it enters the txt variable as a new command.
Is there a system variable or drawing variable I am missing?

Is there a way to fetch the attribute of that content block attached to the Mleader last inserted and put the txt variable in it?

Thanks.

Dlanor

  • Bull Frog
  • Posts: 263
I am using AutoCAD 2012. I altered the code in my first post to account for the ATTREQ system variable which may have been affecting the outcome. Have you tested this changed code and is it now working as required?

jodeknudt

  • Mosquito
  • Posts: 5
I have tested it, still asks me for the edit attribute. I know why.

Code: [Select]
(mapcar 'setvar sv_lst (list "BLUSAPPARAAT" "BLUSAPPARATEN" 1)) needs to be set to 0.

Following Statement still does not enter txt variable.
Code: [Select]
(vl-cmdf "_mleader" arp lap txt)
Code - Auto/Visual Lisp: [Select]
  1. (defun c:2ml ( / oobj sv_lst sv_vals txt arp lap)
  2.   (setq sv_lst (list 'cmleaderstyle 'clayer 'attreq)
  3.         sv_vals (mapcar 'getvar sv_lst)
  4.         oobj (vlax-ename->vla-object (car (entsel)))
  5.         txt (vlax-get oobj 'textstring) ;;; select content from text object
  6.         arp (getpoint "\nPick Arrow Location: ")
  7.         lap (getpoint "\nPick Text Location: ")
  8.   ) ;end_setq
  9.   (mapcar 'setvar sv_lst (list "BLUSAPPARAAT" "BLUSAPPARATEN" 0))
  10.   (vl-cmdf "_mleader" arp lap txt)
  11.   (mapcar 'setvar sv_lst sv_vals)
  12.   (princ)
  13. )

jodeknudt

  • Mosquito
  • Posts: 5
SOLVED!  :yay!:

This script uses the attdia sysvar to turn off the dialog window this allows to insert txt in de commandline.
the first selected text object is deleted.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:2ml ( / oobj sv_lst sv_vals txt arp lap)
  2.   (setq sv_lst (list 'cmleaderstyle 'attdia) ;saves current mleaderstyle + attdia atribute.
  3.         sv_vals (mapcar 'getvar sv_lst)
  4.         oobj (vlax-ename->vla-object (car (entsel)))
  5.         txt (vlax-get oobj 'textstring) ;;; select content from text object
  6.         arp (getpoint "\nPick Arrow Location: ")
  7.         lap (getpoint "\nPick Text Location: ")
  8.   ) ;end_setq
  9.   (mapcar 'setvar sv_lst (list "BLUSAPPARAAT" 0))
  10.   (vl-cmdf "_mleader" arp lap txt)
  11.   (mapcar 'setvar sv_lst sv_vals)
  12.   (entdel (vlax-vla-object->ename oobj))
  13.   (princ)
  14. )