Jump to content

Recommended Posts

Posted (edited)

Hi all,

 

I'm having an issue with fuzzy text on MULTILEADERS. I have a lisp here that can fix the fuzzyness of MTEXT objects but having trouble with MULTILEADERS. It says:

<< Error: ActiveX Server returned the error: unknown name: Normal >>

 

See the attached drawing and an image of what I see.

 

FuzzyMleaderText.thumb.png.daeac8f26e21d815c2a27859f17d0f0b.png

 

 

Here's the code that works for MTEXT.

(vl-load-com)

;;
;; Thread here: https://www.cadtutor.net/forum/topic/65093-mtext-normal-value-is-it-possible-to-change-this-to-0/
;;
;; TO DO:
;; - Make this work for MLEADERS
;; - Make this work for BLOCKS
;; - Output count of modified entities

(defun c:FXNormal_To_0 (/ *error* acDoc cnt enm mtextNormal mtextObject newNormal ss1 var_cmdecho) 

  (defun *error* (errmsg) 
    (and acDoc (vla-EndUndoMark acDoc))
    (and errmsg 
         (not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*"))
         (princ (strcat "\n<< Error: " errmsg " >>\n"))
    )
    (setvar 'cmdecho var_cmdecho)
  )

  (setq var_cmdecho (getvar "cmdecho"))
  (setvar 'cmdecho 0)

  (setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (or (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc))

  (if (setq ss1 (ssget "_:L" '((0 . "MTEXT,MULTILEADER")))) 

    (progn 

      (repeat (setq cnt (sslength ss1)) 

        (setq cnt (1- cnt))
        (setq enm (_dxf -1 (entget (ssname ss1 cnt))))

        (setq mtextObject (vlax-ename->vla-object enm))

        (setq newNormal (vlax-3d-point 0 0 1))
        (vla-put-Normal mtextObject newNormal)
        (vla-Update mtextObject)
      )
    ) ;; progn
  ) ;; if

  (vla-EndUndoMark acDoc)

  (*error* nil)
  (princ)
)

;; -----------------------------------------------------------------------
;; ----------------------=={ Functions START }==--------------------------

;;----------------------------------------------------------------------;;
;; _dxf
;; Finds the association pair, strips 1st element
;; args   - dxfcode elist
;; Example  - (_dxf -1 (entget (ssname (ssget) 0)))
;; Returns  - <Entity name: xxxxxxxxxxx>

(defun _dxf (code elist) 
  (cdr (assoc code elist))
)

(c:FXNormal_To_0) ;; Unlbock for testing

 

 

If I explode the MLEADER and run the above code the MTEXT is fixed so this issue is with the normal of the TEXT object of the MLEADER.

 

Fuzzy Mleader Text.dwg

Edited by 3dwannab
Posted
1 hour ago, SLW210 said:

See if this gets you there...Modify Text in Multileader

 

Unfortunately not, If I could get the handle of the MTEXT entity inside I could manage to get this working but I'm struggling to get that entity.

 

My horrible stab at it:

(defun C:TEST (/ ss mlent mldata tml textContents textEnt entType) 
  (if (setq ss (ssget "_:L" '((0 . "MULTILEADER")))) 
    (repeat (setq n (sslength ss))  ; then
      (setq mlent  (ssname ss (setq n (1- n)))
            mldata (entget mlent)
      ) ; setq

      ;; Easy to get the contents of the text
      (setq textContents (cdr (assoc 304 mldata)))
      (princ textContents)

      ;; Struggling to get the entity. I think it's in 340, nawt sure!
      (setq textEnt (cdr (assoc 340 mldata)))
      (princ textEnt)

      (setq entType (cdr (assoc 0 (entget textEnt))))
      (princ entType) ;; Returns STYLE
    ) ; repeat
  ) ; if
  (princ)
); defun

(C:TEST)

 

Posted (edited)

Just guessing your mtext has been created with a non world UCS, just compare use (entget (car (entsel))) pick the mtext and look at the say 111 dxf plus some other dxf codes, 

 

image.png.461914ac99c77632a7e0df6f67d9bed3.png

Edited by BIGAL
Posted (edited)
13 hours ago, BIGAL said:

Just guessing your mtext has been created with a non world UCS, just compare use (entget (car (entsel))) pick the mtext and look at the say 111 dxf plus some other dxf codes, 

 

Oh, I see these.

(13 1.0 3.08442e-12 1.37197e-21)
(111 1.0 3.08442e-12 1.37197e-21)
(11 1.0 3.08442e-12 1.37197e-21)

 

(entget (car (entsel))) from MULTILEADER

 

((-1 . <Entity name: 25801b84dc0>) (0 . "MULTILEADER") (330 . <Entity name: 25802f111f0>) (5 . "2B89BC") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "AN_text") (100 . "AcDbMLeader") (270 . 2) (300 . "CONTEXT_DATA{") (40 . 15.0) (10 5634.1 -37328.7 1.02898e-19) (41 . 30.0) (140 . 18.75) (145 . 30.0) (174 . 1) (175 . 1) (176 . 0) (177 . 0) (290 . 1) (304 . "{\\LKICK BOARD} 80 x 19mm kick board, Formica bonded MDF both sides, clipped to cabinet legs.") (11 0.0 -4.44806e-10 1.0) (340 . <Entity name: 25801b042a0>) (12 5664.1 -37309.4 0.0) (13 1.0 3.08442e-12 1.37197e-21) (42 . 3.08442e-12) (43 . 1200.0) (44 . 0.0) (45 . 1.0) (170 . 1) (90 . -1073741824) (171 . 1) (172 . 5) (91 . -1073741824) (141 . 0.0) (92 . 0) (291 . 0) (292 . 0) (173 . 0) (293 . 0) (142 . 0.0) (143 . 0.0) (294 . 0) (295 . 0) (296 . 0) (110 2120.96 -32285.1 0.0) (111 1.0 3.08442e-12 1.37197e-21) (112 -3.08442e-12 1.0 4.44806e-10) (297 . 0) (302 . "LEADER{") (290 . 1) (291 . 1) (10 5559.1 -37328.7 0.0) (11 1.0 3.08442e-12 1.37197e-21) (90 . 0) (40 . 75.0) (304 . "LEADER_LINE{") (10 4468.6 -37112.2 0.0) (10 4468.6 -37328.7 0.0) (91 . 0) (170 . 1) (92 . -1056964608) (340 . <Entity name: 0>) (171 . -2) (40 . 0.0) (341 . <Entity name: 0>) (93 . 0) (305 . "}") (271 . 0) (303 . "}") (272 . 9) (273 . 9) (301 . "}") (340 . <Entity name: 25802f13510>) (90 . 17204224) (170 . 1) (91 . -1023410166) (341 . <Entity name: 25802f0d5a0>) (171 . 20) (290 . 1) (291 . 1) (41 . 5.0) (342 . <Entity name: 25802ef93a0>) (42 . 1.25) (172 . 2) (343 . <Entity name: 25801b042a0>) (173 . 1) (95 . 1) (174 . 1) (175 . 0) (92 . -1073741824) (292 . 0) (93 . -1056964608) (10 1.0 1.0 1.0) (43 . 0.0) (176 . 0) (293 . 0) (294 . 0) (178 . 0) (179 . 1) (45 . 15.0) (271 . 0) (272 . 9) (273 . 9) (295 . 1))


(entget (car (entsel))) from exploded MULTILEADER. <Entity name: 25802f111f0> is in the MULTILEADER above but this is a BLOCK RECORD. Entity 25815951bd0 which is the MTEXT object is nowhere to be seen in the above dump.

 

((-1 . <Entity name: 25815951bd0>) (0 . "MTEXT") (330 . <Entity name: 25802f111f0>) (5 . "3AE9B5") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "AN_text") (100 . "AcDbMText") (10 5664.1 -37309.4 0.0) (40 . 30.0) (41 . 1200.0) (46 . 0.0) (71 . 1) (72 . 5) (1 . "{\\LKICK BOARD} 80 x 19mm kick board, Formica bonded MDF both sides, clipped to cabinet legs.") (7 . "AN_Century-Gothic") (210 0.0 -4.44806e-10 1.0) (11 1.0 3.08442e-12 1.37197e-21) (42 . 1163.29) (43 . 91.3392) (50 . 3.08442e-12) (73 . 1) (44 . 1.0))

 

Edited by 3dwannab
Posted (edited)

Slight update, see below.

 

; Dump from MLEADER
(11 0.0 -4.44806e-10 1.0)
(112 0.0 1.0 4.44806e-10)

;; This is the Property dump from MTEXT after the MLEADER is exploded.
Normal = (0.0 -4.44806e-10 1.0)

 

So I'm onto something, or else barking up the wrong tree.🌳🐕

Edited by 3dwannab
Posted

I have this at Home....

 

;;; list object properties
;;;
;;; By SLW210 (Steve Wilson)
;;;
;;; Works for a lot of objects
;;;
;;; https://www.cadtutor.net/forum/topic/90639-text-fuzzy-on-multileaders/?do=findComment&comment=650190

(defun c:LOP () (c:listobjectproperties))

(defun c:listobjectproperties ()
  (vl-load-com)
  (setq ss (ssget)) ; Prompt user to select objects
  (if ss
    (progn
      (setq n (sslength ss)) ; Get the number of selected objects
      (princ (strcat "\nNumber of objects selected: " (itoa n)))
      (repeat n
        (setq ent (ssname ss (setq i (if (not i) 0 (1+ i))))) ; Get the next selected object
        (setq obj (vlax-ename->vla-object ent)) ; Convert to VLA object
        (setq objName (vla-get-ObjectName obj)) ; Get object type

        ;; Print properties
        (princ (strcat "\n\nProperties of " objName ":"))
        (princ (strcat "\nHandle: " (vla-get-Handle obj)))
        (princ (strcat "\nColor: " (itoa (vla-get-Color obj))))
        (princ (strcat "\nLayer: " (vla-get-Layer obj)))
        (princ (strcat "\nLinetype: " (vla-get-Linetype obj)))

        ;; Additional properties based on object type
        (cond
          ;; MText
          ((equal objName "AcDbMText")
           (princ (strcat "\nText: " (vla-get-TextString obj))))
          ;; Line
          ((equal objName "AcDbLine")
           (princ (strcat "\nStart Point: " (vl-princ-to-string (vlax-get obj 'StartPoint))))
           (princ (strcat "\nEnd Point: " (vl-princ-to-string (vlax-get obj 'EndPoint)))))

          ;; Arc
          ((equal objName "AcDbArc")
           (princ (strcat "\nCenter Point: " (vl-princ-to-string (vlax-get obj 'Center))))
           (princ (strcat "\nRadius: " (rtos (vlax-get obj 'Radius) 2 4)))
           (princ (strcat "\nStart Angle: " (rtos (vlax-get obj 'StartAngle) 2 4)))
           (princ (strcat "\nEnd Angle: " (rtos (vlax-get obj 'EndAngle) 2 4))))
        )
      )
      (princ)
    )
    (princ "\nNo objects selected.")
  )
  (princ)
)

 

  • Like 1
Posted (edited)

I got the fuzzy text fixed but if I change the z value of this (112 0.0 1.0 4.44806e-10) of the mleader it scews it up.  Edit: I was the one who messed up.

 

But I was lazy and asked chatGTP.


Original code from chatGTP:

(defun c:ChangeMLeaderDXF11 ()
  (setq ent (car (entsel "\nSelect MLeader: "))) ; Prompt user to select an MLeader
  (setq entData (entget ent))                   ; Get the entity's data list
  
  ;; Find the DXF code 11 entry (direction vector)
  (if (setq dxf11 (assoc 11 entData))
    (progn
      ;; Extract the current vector components
      (setq oldVector (cdr dxf11))
      ;; Define the new Y-component value
      (setq newY -1.0) ; Example new Y value
      
      ;; Create the new vector with the modified Y component
      (setq newVector (list (nth 0 oldVector) newY (nth 2 oldVector)))
      
      ;; Replace the old vector with the new vector
      (setq newEntData (subst (cons 11 newVector) dxf11 entData))
      
      ;; Apply the changes to the MLeader entity
      (entmod newEntData)
      (entupd ent)  ; Update the entity to reflect the change
    )
    (princ "\nDXF code 11 not found in MLeader entity.")
  )
  
  (princ) ; Clean exit
)

 

 ChatGTP code cleaned up:

(defun C:TEST (/ blk dxf11 ent entData mleader ent n newEntData newVector newY oldVector ss text-entities) 
  (if (setq ss (ssget "_:L" '((0 . "MULTILEADER")))) 
    (repeat (setq n (sslength ss)) 

      (setq ent (ssname ss (setq n (1- n))))
      (setq entData (entget ent)) ; Get the entity's data list

      (if (setq dxf11 (assoc 11 entData)) 
        (progn 

          ;; Extract the current vector components
          (setq oldVector (cdr dxf11))
          ;; Define the new Y-component value
          (setq newY 0) ; Example new Y value

          ;; Create the new vector with the modified Y component
          (setq newVector (list (nth 0 oldVector) newY (nth 2 oldVector)))

          ;; Replace the old vector with the new vector
          (setq newEntData (subst (cons 11 newVector) dxf11 entData))

          ;; Apply the changes to the MLeader entity
          (entmod newEntData)
          (entupd ent) ; Update the entity to reflect the change
        )
      )
    ) ; repeat
  ) ; if
  (princ)
) ; defun
(C:TEST)

 

Edited by 3dwannab
Posted (edited)

Finished code:

 

(vl-load-com)
;;
;; Thread here: https://www.cadtutor.net/forum/topic/65093-mtext-normal-value-is-it-possible-to-change-this-to-0/
;; Credit goes to user rlx for the original answer here: https://www.cadtutor.net/forum/topic/65093-mtext-normal-value-is-it-possible-to-change-this-to-0/?do=findComment&comment=536399
;;
;; Thread here to troubleshoot MULTILEADERS normals: https://www.cadtutor.net/forum/topic/90639-text-fuzzy-on-multileaders/
;;
;; 3dwannab mod 2024.08.30
;; - Added support for MULTTLEADERS
;;
;; TO DO:
;; - Make this work for ENTITIES inside BLOCKS
;;

(defun c:FXNormal_To_0 (/ *error* acDoc cnt dxf11 dxf112 ent entData mtextObj newEntData newNormal3dPt newNormalVal newVector oldVector ss typ var_cmdecho) 

  (defun *error* (errmsg) 
    (and acDoc (vla-EndUndoMark acDoc))
    (and errmsg 
         (not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*"))
         (princ (strcat "\n<< Error: " errmsg " >>\n"))
    )
    (setvar 'cmdecho var_cmdecho)
  )

  ;; Start the undo mark here
  (setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (or (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc))

  ;; Get any system variables here
  (setq var_cmdecho (getvar "cmdecho"))
  (setvar 'cmdecho 0)

  (if (setq ss (ssget "_:L" '((0 . "MTEXT,MULTILEADER")))) 

    (progn 

      (repeat (setq cnt (sslength ss)) 

        (setq cnt (1- cnt))
        (setq ent (_dxf -1 (entget (ssname ss cnt))))
        (setq entData (entget ent)) ; Get the entity's data list

        (setq mtextObj (vlax-ename->vla-object ent))
        (setq typ (cdr (assoc 0 (entget ent))))

        (cond 
          ((= typ "MTEXT")

           (setq newNormal3dPt (vlax-3d-point 0 0 1))
           (vla-put-Normal mtextObj newNormal3dPt)
           (vla-Update mtextObj)
          ) ;; end cond MTEXT

          ;; Condition for MULTILEADERS. There is no normal property so you have to modify the 112 dxf Z value and the 11 dxf Y value.
          ;; Note, you have to do 112 first and then 11 second, otherwise it won't work.
          ((= typ "MULTILEADER")

           (setq newNormalVal 0.0) ; Set this to 0.0

           (if (setq dxf112 (assoc 112 entData)) 
             (progn 
               (setq oldVector (cdr dxf112)) ;; Extract the current vector components
               (setq newVector (list (nth 0 oldVector) (nth 1 oldVector) newNormalVal)) ;; Create the new vector with the modified Z component
               (setq newEntData (subst (cons 112 newVector) dxf112 entData)) ;; Replace the old vector with the new vector
               (entmod newEntData) ;; Apply the changes to the MLeader entity
               (entupd ent) ; Update the entity to reflect the change
             )
           )

           (if (setq dxf11 (assoc 11 entData)) 
             (progn 
               (setq oldVector (cdr dxf11)) ;; Extract the current vector components
               (setq newVector (list (nth 0 oldVector) newNormalVal (nth 2 oldVector))) ;; Create the new vector with the modified Y component
               (setq newEntData (subst (cons 11 newVector) dxf11 entData)) ;; Replace the old vector with the new vector
               (entmod newEntData) ;; Apply the changes to the MLeader entity
               (entupd ent) ; Update the entity to reflect the change
             )
           )
          ) ;; end cond MULTILEADER
        )
      )
    ) ;; progn
  ) ;; if ssget

  (if ss 
    (progn 
      (princ (strcat ">> " (itoa (sslength ss)) (if (> (sslength ss) 1) "  objects normals are" "  objects normal is") " fixed <<\n"))
      (sssetfirst nil ss)
      (command "_.regen")
    )
  )

  (vla-EndUndoMark acDoc)

  (*error* nil)
  (princ)
)

;; -----------------------------------------------------------------------
;; ----------------------=={ Functions START }==--------------------------

;;----------------------------------------------------------------------;;
;; _dxf
;; Finds the association pair, strips 1st element
;; args   - dxfcode elist
;; Example  - (_dxf -1 (entget (ssname (ssget) 0)))
;; Returns  - <Entity name: xxxxxxxxxxx>

(defun _dxf (code elist) 
  (cdr (assoc code elist))
)

; (c:FXNormal_To_0) ;; Unlbock for testing

 

Edited by 3dwannab

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