Jump to content

Recommended Posts

Posted

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!)

Posted

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)
)

Posted

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

Posted

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.

Posted

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)

Posted

Like Roy_043 but no need for _none

 

(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
... your code
(setvar 'osmode oldsnap)

Posted

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)

Posted

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 :)

Posted
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. :)

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...