Author Topic: mLeader LISP Issue  (Read 4607 times)

0 Members and 1 Guest are viewing this topic.

cmwade77

  • Swamp Rat
  • Posts: 1443
mLeader LISP Issue
« on: February 22, 2019, 06:56:21 PM »
This is one very small snipet of code from a routine I am currently working on. I am having errors when trying to insert text after changing content type from block to mtext.

Code: [Select]
(defun c:mletest (/ Ent1 *mlObj* *Text*)
    (while (not Ent1)
        (setq Ent1 (entsel "\rPlease select mleader:"))
    )
    (setq *mlObj* (vlax-ename->vla-object (car Ent1)))
    (if (= (vla-get-contenttype *mlObj*) acblockcontent)
        (progn
           (vla-put-contenttype *mlObj* acmtextcontent)
           (setq *Text* (getstring T "\nEnter text:"))
            (if *Text*
                (vla-put-TextString *mlObj* *Text*)        ;******** This line seems to cause the mleader to be erased or to return an error of Description Not Provided
                (vla-put-TextString *mlObj* "TEMP\\PTEXT") ;******** This line seems to cause the mleader to be erased or to return an error of Description Not Provided
            )
        )
    )
)

You will find the error occurs after entering text, perhaps someone can tell me what I am doing wrong.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2120
  • class keyThumper<T>:ILazy<T>
Re: mLeader LISP Issue
« Reply #1 on: February 22, 2019, 09:02:18 PM »
Does the Leader disappear or the Text ??

And only when you hit ENTER or SPACE at the Prompt ??

ENTER or SPACE using the T flag sets *text* as an empty String ie ""
So the if will not fail and will attempt to use the empty string as the MText value ...

Just a wild guess ...

otherwise, can you post the drawing with the original Multileader please.

ADDED:
I wonder if you need to actually change the MleaderStyle from one with a block to one with MText ???
« Last Edit: February 22, 2019, 09:30:00 PM by kdub »
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: mLeader LISP Issue
« Reply #2 on: February 25, 2019, 12:17:29 PM »
It doesn't matter if there is a space in the text or not, it doesn't work either way. Yes, I would expect an empty string to fail, as I said this is just one small piece of code, I actually have checks in place to make sure the string isn't empty in the full code.

The style never changes no matter if it is a block or mtext.

I have attached a drawing with the original mleader in it, the ones with the blocks can't seem to be changed to having MTEXT and I am not sure why.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: mLeader LISP Issue
« Reply #3 on: February 25, 2019, 04:28:24 PM »
Did you ever get this to work? I'd imagine you can't just change the content type .. I get strange results here ( no contents property ).

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: mLeader LISP Issue
« Reply #4 on: February 25, 2019, 04:29:50 PM »
You can change to a block, but changing back to mText is where there seems to be a problem.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: mLeader LISP Issue
« Reply #5 on: February 25, 2019, 04:41:51 PM »
The mleader definitely does not like the change from block to mtext type:

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: mLeader LISP Issue
« Reply #6 on: February 25, 2019, 05:27:17 PM »
Well, I decided to roll my own method of making this work. Basically, this creates a new leader using the same properties as the existing leader, then erases the old leader. It is a bit of a kludge, but it works as near as I can tell.

Code: [Select]
(defun c:mletest (/ Ent1 *mlObj* *Text* *NewMlObj*)
    (while (not Ent1)
        (setq Ent1 (entsel "\rPlease select mleader:"))
    )
    (setq *mlObj* (vlax-ename->vla-object (car Ent1)))
    (setq *Text* (getstring T "\nEnter text:"))
    (if (= (vla-get-contenttype *mlObj*) acblockcontent)
        (progn
            (setq *NewMlObj* (MleaderBlockToMtext *mlObj* *Text*))
            (if *NewMlObj*
                (setq *mlObj* *NewMlObj*
                      *NewMlObj* nil
                )
            )
        )
    )
)

(defun MleaderBlockToMtext (*MlObj* *Text* / *ThisDrawing* *Space* *NewMlObj* *InsPt* NewPoints2 *Pt1* *FxPt* *MtObj* *ArrowheadSize* *ArrowheadType* *DogLegged* *DogLegLength* *EntityTransparency* *LandingGap* *Layer* *LeaderLineColor* *LeaderLineType* *LeaderLineWeight* *LeaderType* *Linetype* *LinetypeScale* *Lineweight* *PlotStyleName* *StyleName* *TextWidth* *NewPoints*)
;Written by: Chris Wade - 02/25/2019
;Changes leader content from Block to mText
;Usage: (setq *NewMlObj* (MleaderBlockToMtext *mlObj* *Text*))
    (if *MlObj*
        (progn
            (setq *ThisDrawing* (vla-get-activedocument (vlax-get-acad-object)) ;_ Set Drawing and Space
              *Space* (vlax-get-property *ThisDrawing* (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace)); Code adjustment from Lee Mac at: http://www.theswamp.org/index.php?topic=54349.msg589159#msg589159
        )
            (setq *ArrowheadSize* (vla-get-ArrowheadSize *MlObj*)
                  *ArrowheadType* (vla-get-ArrowheadType *MlObj*)
                  *DogLegged* (vla-get-DogLegged *MlObj*)
                  *DogLegLength* (vla-get-DogLegLength *MlObj*)
                  *EntityTransparency* (vla-get-EntityTransparency *MlObj*)
                  *LandingGap* (vla-get-LandingGap *MlObj*)
                  *Layer* (vla-get-Layer *MlObj*)
                  *LeaderLineColor* (vla-get-LeaderLineColor *MlObj*)
                  *LeaderLineType* (vla-get-LeaderLineType *MlObj*)
                  *LeaderLineWeight* (vla-get-LeaderLineWeight *MlObj*)
                  *LeaderType* (vla-get-LeaderType *MlObj*)
                  *Linetype* (vla-get-Linetype *MlObj*)
                  *LinetypeScale* (vla-get-LinetypeScale *MlObj*)
                  *Lineweight* (vla-get-Lineweight *MlObj*)
                  *PlotStyleName* (vla-get-PlotStyleName *MlObj*)
                  *StyleName* (vla-get-StyleName *MlObj*)
                  *TextWidth* 0
                  *NewPoints* (vlax-make-safearray vlax-vbDouble '(1 . 6))
                  *NewPoints* (vla-GetLeaderLineVertices *mlObj* 0)
                  NewPoints2 (vlax-safearray->list (vlax-variant-value *NewPoints*))
                  *Pt1* (list (nth 0 NewPoints2) (nth 1 NewPoints2) (nth 2 NewPoints2))
      *FxPt* (list (nth 3 NewPoints2) (nth 4 NewPoints2) (nth 5 NewPoints2))
                  *NewMlObj* (vla-AddMLeader *Space* *NewPoints* 0)
            )
            (if *NewMlObj*
                (progn
                    (if (> (car *Pt1*) (car *FxPt*))
                        (progn
                            (vla-put-dogleglength *NewMlObj* 0); This code is from http://www.theswamp.org/index.php?topic=31348.msg369336#msg369336
                    (vla-SetDogLegDirection *NewMlObj* 0 (vlax-3D-point (list (if (<= (car *pt1*) (car *FxPT*)) 1 -1) 0 0))); Code from: http://www.theswamp.org/index.php?topic=30817.0
                    (vla-put-dogleglength *NewMlObj* *DogLegLength*); This code is from http://www.theswamp.org/index.php?topic=31348.msg369336#msg369336
    )
)
(vla-put-textstring *NewMlObj* *Text*)
(if (> (car *Pt1*) (car *FxPt*))
    (vla-put-TextJustify *NewMlObj* acAttachmentPointTopRight)
)
                    (vla-put-StyleName *NewMlObj* *StyleName*)
                    (vla-put-ArrowheadSize *NewMlObj* *ArrowheadSize*)
                    (vla-put-ArrowheadType *NewMlObj* *ArrowheadType*)
                    (vla-put-EntityTransparency *NewMlObj* *EntityTransparency*)
                    (vla-put-LandingGap *NewMlObj* *LandingGap*)
                    (vla-put-Layer *NewMlObj* *Layer*)
                    (vla-put-LeaderLineColor *NewMlObj* *LeaderLineColor*)
                    (vla-put-LeaderLineType *NewMlObj* *LeaderLineType*)
                    (vla-put-LeaderLineWeight *NewMlObj* *LeaderLineWeight*)
                    (vla-put-Linetype *NewMlObj* *Linetype*)
                    (vla-put-LinetypeScale *NewMlObj* *LinetypeScale*)
                    (vla-put-Lineweight *NewMlObj* *Lineweight*)
                    (if (= (getvar "PSTYLEMODE") 0)
                        (vla-put-PlotStyleName *NewMlObj* *PlotStyleName*)
                    )
                    (vla-SetLeaderLineVertices *NewMlObj* 0 *NewPoints*)
                    (vla-delete *MlObj*)
                )
            )
            *NewMlObj*
        )
    )
)

ronjonp

  • Needs a day job
  • Posts: 7526
Re: mLeader LISP Issue
« Reply #7 on: February 25, 2019, 06:05:20 PM »
Off topic question, but why do you use *var*  for all your variables? I've always interpreted that naming convention as a global.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: mLeader LISP Issue
« Reply #8 on: February 25, 2019, 06:09:35 PM »
It is actually part of a larger routine where I am using them as a naming convention for a specific reason. Basically in my larger routine the *var* represent items that get reused throughout the routine and complimentary routines, so basically I guess they are global variables, you just don't get to see that in the small extract and I kept the variable names consistent so that I wouldn't have to go back and change them all to incorporate into my larger routine.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2120
  • class keyThumper<T>:ILazy<T>
Re: mLeader LISP Issue
« Reply #9 on: February 25, 2019, 09:37:45 PM »
Off topic question, but why do you use *var*  for all your variables? I've always interpreted that naming convention as a global.

Ditto me Ron. Usually for variables that are static.
I use a unique prefix for project specific globals ... makes it easy to audit or nullify.
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2120
  • class keyThumper<T>:ILazy<T>
Re: mLeader LISP Issue
« Reply #10 on: February 25, 2019, 09:42:42 PM »
Well, I decided to roll my own method of making this work. Basically, this creates a new leader using the same properties as the existing leader, then erases the old leader. It is a bit of a kludge, but it works as near as I can tell.

I came to the conclusion that I'd do it the same way.
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: mLeader LISP Issue
« Reply #11 on: February 26, 2019, 10:28:53 AM »
It is actually part of a larger routine where I am using them as a naming convention for a specific reason. Basically in my larger routine the *var* represent items that get reused throughout the routine and complimentary routines, so basically I guess they are global variables, you just don't get to see that in the small extract and I kept the variable names consistent so that I wouldn't have to go back and change them all to incorporate into my larger routine.
Cool .. FWIW you could simplify your properties get and set with something like so:
Code - Auto/Visual Lisp: [Select]
  1. (setq ml (vlax-ename->vla-object (car (entsel))))
  2. ;; Get vals
  3. (setq v (mapcar '(lambda (x) (cons x (vlax-get ml x)))
  4.                 '(arrowheadsize     arrowheadtype     doglegged         dogleglength
  5.                   entitytransparency                  landinggap        layer
  6.                   leaderlinecolor   leaderlinetype    leaderlineweight  leadertype
  7.                   linetype          linetypescale     lineweight        plotstylename
  8.                   stylename         textwidth
  9.                  )
  10.         )
  11. )
  12. (setq newml (vlax-ename->vla-object (car (entsel))))
  13. ;; Set vals on new mleader
  14. (mapcar '(lambda (x) (vl-catch-all-apply 'vlax-put (list newml (car x) (cdr x)))) v)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: mLeader LISP Issue
« Reply #12 on: February 27, 2019, 02:27:56 PM »
Cool, thank you, some of those properties won't work that way due to bugs in how LISP handles mLeaders in AutoCAD (particularly the dogleglength), but many will.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: mLeader LISP Issue
« Reply #13 on: March 04, 2019, 01:02:17 PM »
I am getting more of the routine down, although I still haven't implemented ronjonp's suggestion yet, but I am having and issue where text gets reset when cycling from the mtext content type to a block style.

I have attached the LISP routine and the required drawing here if someone can help me figure out where the issue is, I would greatly appreciate it.

Here is a video of the problem:
https://autode.sk/2C6QGo2
« Last Edit: March 04, 2019, 01:11:16 PM by cmwade77 »