SammyC Posted December 1, 2017 Posted December 1, 2017 Hey Guys, first time posting. This forum has helped me out in the past, and I've completely hit a wall. My problem is with multi-leaders. I convert a lot of .dwg files into .shp files and there isn't anyway export multi-leaders directly. So I've been trying to build some LISP code to place the text of the multi-leader at the exact location it points to (doesn't need to be pretty, it just needs the justify point of the text to be the right location). This is way beyond my level of expertise. Any help would be greatly appropriated (Or if a simpler solution is hidden somewhere, that would be great to!) Quote
benhubel Posted December 6, 2017 Posted December 6, 2017 I assume that the explode option works for you but, in case it doesn't, I decided to play around with it. This might not be elegant, but I believe it can help you get started. I've only tested it a little bit. I went a little overboard with the comments, but I figured it wouldn't hurt. ;MLeaderTest (defun c:mltest ( / ss i e p1 height angle contents ) (setq ss (ssget '(( 0 . "MULTILEADER" )))) ;get selection of multileaders (setq i 0) ;set loop index (repeat (sslength ss) ;loop through each selected entity (setq e (ssname ss i)) ;get current entity (setq p1 (cdr (assoc 110 (entget e)))) ;set p1 to the point coordinates that the leader is pointing to (setq height (cdr (assoc 41 (entget e)))) ;set text height (setq angle 0) ;this defaults the rotation angle to be 0 (setq contents (cdr (assoc 304 (entget e)))) ;get text contents (command "text" p1 height angle contents) ;create a new text object based on gathered info (command "erase" e "") ;erase Mleader entity (setq i (1+ i)) ;increment index ) (princ) ) Quote
SammyC Posted December 7, 2017 Author Posted December 7, 2017 Explode doesn't work. It places the text at the exact position it was while part of the Multileader. Appreciate the help benhubel! And the comments (useful for a learning novice). So weirdly it works perfectly on maybe half of the multi-leaders I have in my current drawing. The other half are placed in really inconsistent places, sometimes quite far from the Multi-leader itself. Cant figure out what could be causing the inconsistency. I've attached my test .dwg so you can have a look. LeaderTesting.dwg Quote
benhubel Posted December 7, 2017 Posted December 7, 2017 I'm also still learning, so I'm not entirely sure what the cause is, but it appears as if that's a result of the leader point being moved after the leader is placed. I bet I used the wrong assoc code since it worked in my initial testing. I'll see if I can figure out a fix. Quote
Roy_043 Posted December 7, 2017 Posted December 7, 2017 Commands called inside a Lisp routine will respect the OSMODE setting. To avoid undesirable object snaps you can use: (command "text" "_non" p1 height angle contents) Quote
BIGAL Posted December 8, 2017 Posted December 8, 2017 Like Roy_043 but no need for _none (setq oldsnap (getvar 'osmode)) (setvar 'osmode 0) ... your code (setvar 'osmode oldsnap) Quote
ronjonp Posted December 8, 2017 Posted December 8, 2017 Here's a quickie .. happy Friday! (defun c:foo (/ r o n) (if (setq n (ssget ":L" '((0 . "MULTILEADER")))) (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex n))) (setq o (vlax-ename->vla-object x)) (setq r (vlax-invoke o 'getleaderlinevertices 0)) (if (entmakex (list '(0 . "TEXT") '(100 . "AcDbEntity") '(67 . 0) (cons 8 (vla-get-layer o)) '(100 . "AcDbText") (list 10 (car r) (cadr r) (caddr r)) (cons 40 (vla-get-textheight o)) (cons 1 (vla-get-textstring o)) (cons 50 (vla-get-textrotation o)) '(41 . 1.0) '(51 . 0.0) (cons 7 (vla-get-textstylename o)) '(71 . 0) '(72 . 0) '(11 0.0 0.0 0.0) '(100 . "AcDbText") '(73 . 0) ) ) (entdel x) ) ) ) (princ) ) (vl-load-com) Quote
SammyC Posted December 8, 2017 Author Posted December 8, 2017 ronjonp I haven't got a clue what half of that code means, but it works absolutely beautifully. I really appreciate the help everyone, you've made my exporting process so much more flexible, plus I've learnt some more LISP stuff. Win-Win. Happy Friday everyone Quote
ronjonp Posted December 8, 2017 Posted December 8, 2017 ronjonp I haven't got a clue what half of that code means, but it works absolutely beautifully. I really appreciate the help everyone, you've made my exporting process so much more flexible, plus I've learnt some more LISP stuff. Win-Win. Happy Friday everyone Glad to help out. Quote
Recommended Posts
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.