Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Converting multileader to block lisp

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
yu85.info
565 Views, 10 Replies

Converting multileader to block lisp

Hi. I have a lot of multileader in this DWG attached (Drawing1.dwg). I need to convert all of  them to a certain block I have. I need that the insertion point of  the block will be in the same position of the multileader and to copy a part from the text of the leader to the attribute (I need the diameter information in the text and the IL information) . I have attached an example in another DWG attached (Drawing2.dwg). I did it manually of course. Is there a way to make this conversion with a lisp routine?

Thank you all in advance

Labels (2)
10 REPLIES 10
Message 2 of 11
ec-cad
in reply to: yu85.info

Looks like a large effort (for a freebe), consider a couple of Lisps to get you there.

(1) foreach 'leader', extract insertion point, and text portions you want. Open a .csv file,

write the data there (name it drawingname.csv), and save in current folder.

 

Open a 'new' drawing or template. 

(2) read-in the .csv file, insert your block at the insertion point, and use other columns of info

to fill-in the appropriate Attributes.

 

Sounds simple ?

- But, what 'angle' should the block be inserted ? If the same, then many will be atop one-another.

 

ECCAD

 

Message 3 of 11
yu85.info
in reply to: ec-cad

Thank you sir.

Step (1) will do most of the job. If I could have a CSV  with X, Y, Diameter and IL details I would be very happy. From there I can manage.

Unfortuanlly even that I do not know how to do. Regarding the angle, I don't mind getting all of them in the same angle and do some manually edinting.

 

Message 4 of 11
ec-cad
in reply to: yu85.info

I did a similar task awhile ago for pulling out 'Manhole' data to a .csv.

I posted it here.

Are you OK with editing that Lisp, or do you need assist in function 'decode_MText  ?

If so, I can try messing with it for your drawing1.dwg sample.

 

ECCAD

Message 5 of 11
yu85.info
in reply to: ec-cad

Hi sir, thanks again. If you can help me adjusting your lisp to match my data I would be grateful.

Message 6 of 11
ec-cad
in reply to: yu85.info

I'm on it, may not be today though.

 

ECCAD

Message 7 of 11
Moshe-A
in reply to: yu85.info

@yu85.info  shalom,

 

check this LE2BL  (leader to block)  command.

thanks to great mr Lee Mac who provide the world these magnificent functions [ (LM:UnFormat) & (LM:str->lst)  ]

without them this command would never been made 😀

i also attached drawing14.dwg (your drawing1.dwg) where i fix the units for the drawing and the block, you should fix yours, otherwise this will not work smoothly.

 

enjoy

Moshe

 

 

;;-------------------=={ UnFormat String }==------------------;;
;;                                                            ;;
;;  Returns a string with all MText formatting codes removed. ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  str - String to Process                                   ;;
;;  mtx - MText Flag (T if string is for use in MText)        ;;
;;------------------------------------------------------------;;
;;  Returns:  String with formatting codes removed            ;;
;;------------------------------------------------------------;;

(defun LM:UnFormat ( str mtx / _replace rx )

    (defun _replace ( new old str )
        (vlax-put-property rx 'pattern old)
        (vlax-invoke rx 'replace str new)
    )
    (if (setq rx (vlax-get-or-create-object "VBScript.RegExp"))
        (progn
            (setq str
                (vl-catch-all-apply
                    (function
                        (lambda ( )
                            (vlax-put-property rx 'global     actrue)
                            (vlax-put-property rx 'multiline  actrue)
                            (vlax-put-property rx 'ignorecase acfalse) 
                            (foreach pair
                               '(
                                    ("\032"    . "\\\\\\\\")
                                    (" "       . "\\\\P|\\n|\\t")
                                    ("$1"      . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]")
                                    ("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);")
                                    ("$1$2"    . "\\\\(\\\\S)|[\\\\](})|}")
                                    ("$1"      . "[\\\\]({)|{")
                                )
                                (setq str (_replace (car pair) (cdr pair) str))
                            )
                            (if mtx
                                (_replace "\\\\" "\032" (_replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str))
                                (_replace "\\"   "\032" str)
                            )
                        )
                    )
                )
            )
            (vlax-release-object rx)
            (if (null (vl-catch-all-error-p str))
                str
            )
        )
    )
); LM:UnFormat


;; String to List  -  Lee Mac
;; Separates a string using a given delimiter
;; str - [str] String to process
;; del - [str] Delimiter by which to separate the string
;; Returns: [lst] List of strings
 
(defun LM:str->lst ( str del / pos )
    (if (setq pos (vl-string-search del str))
        (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del))
        (list str)
    )
); LM:str->lst

(vl-load-com)

; leader to block
(defun c:le2bl (/ savAttdia savAttdia ss ename0 ename1 AcDbMultiLeader text doubles p0 val)

 (setvar "cmdecho" 0)
 (command "._undo" "_begin")

 (if (setq ss0 (ssget '((0 . "multileader"))))
  (progn
   (setq savAttdia (getvar "attdia"))
   (setq savAttreq (getvar "attreq"))
   
   (setvar "attdia" 0)
   (setvar "attreq" 0)
   
   (foreach ename0 (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss0)))
    (setq AcDbMultiLeader (vlax-ename->vla-object ename0))
    (setq text (vla-get-textString AcDbMultiLeader))
    (setq doubles (vlax-safearray->list (vlax-variant-value (vla-GetLeaderLineVertices AcDbMultiLeader 0))))
    (setq p0 (list (car doubles) (cadr doubles)))

    (command "._insert" "TASHTIT_B_N" "_None" p0 1 1 0)
    (setq ename1 (entlast))
     
    (foreach val (setq lst (LM:str->lst (LM:unFormat text nil) " "))
     (cond
      ((eq (strcase (substr val 1 3)) "%%C")
       (if (getpropertyvalue ename1 "DIAMETER")
        (setpropertyvalue ename1 "DIAMETER" val)
       )
      ); case
      ((eq (strcase (substr val 1 4)) "I.L=")
       (if (getpropertyvalue ename1 "IL_1")
        (setpropertyvalue ename1 "IL_1" (substr val 5))
       )
      ); case
     ); cond
    ); foreach

    (vlax-release-object AcDbMultiLeader)
   ); foreach

   (setvar "attreq" savAttreq)
   (setvar "attdia" savAttdia)
  ); progn
 ); if

 (command "._undo" "_end")
 (setvar "cmdecho" 1)
  
 (princ)
); c:le2bl

 

 

 

Message 8 of 11
ec-cad
in reply to: yu85.info

I was working on it, but looks like Moshe-A has it solved. Very nice.

I would only change 1 line for the insert, so the new blocks look about the same size.

(command "._insert" "TASHTIT_B_N" "_None" p0 0.05 0.05 0); is what I used.

Does put the block inserts on top of one another at times.

 

ECCAD

Message 9 of 11
Moshe-A
in reply to: ec-cad

@ec-cad  hi,

 

First thank you for the correction but 0.05 looks too small maybe you meant 0.5 but beyond that a scale of 0.5 what does it mean? to me it's means noting cause it does not say if the drawing scale if 1:100 or 1:50 or 1:25 or 1:20.

dimensions \ texts \ leaders \ block symbols \ linetypes all part of annotations, they all should be reference to one global scale. i use dimscale for that matter. for example dimscale = 100 for 1:100, where the dimtxt is 0.18 - 0.20

would produce dim text 18 - 20 units and in plot 1.8 - 2.0 mm when dimscale is 50 produce  the same in plot.

the same would be for block symbols they all should be defined at 1:1 (very small) so at insert they multiplied by dimscale.

 

Moshe

 

 

 

Message 10 of 11
yu85.info
in reply to: Moshe-A

Amazing! 

Thank you so much Moshe!

Message 11 of 11
yu85.info
in reply to: ec-cad

Thank you very much for your help and the correction.

 

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report