Jump to content

Need help converting Mtext objects list (VLA-object?) to selection set


aridzv

Recommended Posts

Hi.

I have a list of Mtext objects that I need to convert to a selection set,and this is the error that I'm getting:

; error : bad argument type <(#<VLA-OBJECT IAcadMText 00000000733971E0> #<VLA-OBJECT IAcadMText 0000000073397560> #<VLA-OBJECT IAcadMText 0000000073396760>)> ; expected SELECTIONSET at [sslength]

 

I've searched for answers and came with this 2 topics (topic1,topic2) but I could't make it work.

I've attached a sample drawing and the full lisp that I'm using.

 

in general,what Im trying to do is this:

1. select text objects

2. passing a list of those objects to a function that convert them to Mtext (I've found this lisp for that).

3. return a list of the Mtext objects to the main program.

(those 3 steps are successful).

4. convert the Mtext to blocks (the function converting the Mtext to block is good - see this topic.), but that function requiered selection set and I have a list...

 

Thanks,

Ari.

     

txtToBlk7.lsp txtToBlk7 test.dwg

Edited by aridzv
Link to comment
Share on other sites

  • aridzv changed the title to Need help converting Mtext objects list (VLA-object?) to selection set
29 minutes ago, mhupp said:

Can you post the code for steps 1-3?

and a sample drawing

Hi.

I've attached both the lisp and a sample drawing in my first comment - can't you see them?

if not I'll attach tem again.

 

about steps 1-3:

     (princ (strcat "\nSelect texts to be replaced with " tagname " Attributed Block:" ));; prompt the user to select the text objects
     (setq sel (ssget "_:L" '((0 . "TEXT")))) ;;creating a list named "sel" of those objects from a user selection.
     (setq sel1 (t2mtx sel));; call the lisp that convert text to Mtext and passing sel list to that lisp,and get the return list into sel1
.
.
.
(defun t2mtx (ss1 / lst usercmd) ;; the function that get the list sel,change the text to Mtext and return the list "sel1"
  ;;  CAB Text to Mtext conversion
  (defun T2M (code)
    ;; code =  dText Alignment code
    (cdr 
      (assoc code
	      '(( 0 ;|acAlignmentLeft        |; . acAttachmentPointBottomLeft)
               ( 1 ;|acAlignmentCenter      |; . acAttachmentPointBottomCenter)
               ( 2 ;|acAlignmentRight       |; . acAttachmentPointBottomRight)
               ( 3 ;|acAlignmentAligned     |; . acAttachmentPointBottomLeft)
               ( 4 ;|acAlignmentMiddle      |; . acAttachmentPointMiddleCenter)
               ( 5 ;|acAlignmentFit         |; . acAttachmentPointBottomLeft)
               ( 6 ;|acAlignmentTopLeft     |; . acAttachmentPointTopLeft)
               ( 7 ;|acAlignmentTopCenter   |; . acAttachmentPointTopCenter)
               ( 8 ;|acAlignmentTopRight    |; . acAttachmentPointTopRight)
               ( 9 ;|acAlignmentMiddleLeft  |; . acAttachmentPointMiddleLeft)
               (10 ;|acAlignmentMiddleCenter|; . acAttachmentPointMiddleCenter) 
               (11 ;|acAlignmentMiddleRight |; . acAttachmentPointMiddleRight)
               (12 ;|acAlignmentBottomLeft  |; . acAttachmentPointBottomLeft)
               (13 ;|acAlignmentBottomCenter|; . acAttachmentPointBottomCenter) 
               (14 ;|acAlignmentBottomRight |; . acAttachmentPointBottomRight))
     ))
  )
  (command "_Undo" "_end")
  (command "_Undo" "_begin")
  ;;(setq ss (ssget '((0 . "TEXT")))) ; get only plain text
  (setq lst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss1))))
  (setq usercmd (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (mapcar
    '(lambda (x)
       (setq obj (vlax-ename->vla-object x)
             ali (vla-get-alignment obj)
             ipt (vlax-get obj 'InsertionPoint)
             apt (vlax-get obj 'Textalignmentpoint)
       )
       (command "txt2mtxt" x "")
       (setq new (vlax-ename->vla-object(entlast)))
       (vla-put-AttachmentPoint new (eval (t2m ali)))
       (if (equal apt '(0.0 0.0 0.0))
         (vlax-put new 'InsertionPoint ipt)
         (vlax-put new 'InsertionPoint apt)
       )
       (vla-put-width new 0.0)
       (setq lstnew (cons new lstnew))
     )
    lst
  )
  (setvar "CMDECHO" usercmd)
  (command "_Undo" "_end")
  (princ)
)

 

Edited by aridzv
Link to comment
Share on other sites

1 hour ago, mhupp said:

Can you post the code for steps 1-3?

and a sample drawing

 

Sorry its been a long night.

no worries... 🙂

Link to comment
Share on other sites

You commented out the part that converts the visual objects back to selection set again.

 

      (setq SS (ssadd))
      (foreach entityToAdd lstnew
      ;;(ssadd entityToAdd lstnew1)
        (ssAdd (vlax-vla-object->ename entityToAdd) SS)
      )
      (princ SS)
      (princ "ggg")
      (repeat (setq int (sslength SS))
        (setq ent (ssname SS (setq int (1- int))))
        (setq ang (cdr (assoc 50 (entget ent))))        ;; get the Mtext Angle (in radians) and set it to the variable ang
        (setq ht (cdr (assoc 40 (entget ent))))         ;; get the Mtext hight (in radians) and set it to the variable ang
        (setq jus (cdr (assoc 72 (entget ent))))

 

Edited by mhupp
Link to comment
Share on other sites

3 hours ago, mhupp said:

You commented out the part that converts the visual objects back to selection set again.

 

      (setq SS (ssadd))
      (foreach entityToAdd lstnew
      ;;(ssadd entityToAdd lstnew1)
        (ssAdd (vlax-vla-object->ename entityToAdd) SS)

 

@mhupp

Thanks!..

it has been a long night indeed... missed the double ssadd.

I've attached here the final lisp.

 

*EDIT:

Two clarifications regarding the previous lisp (txtToBlk7.lsp) comparing to the last one (txtToBlk8.lsp) :

1. in txtToBlk7 I left the line that get the Mtext justify with the DXF assoc code as 72,which will get a text object justify code and not a Mtext one.

    in txtToBlk8 I obviously changed it back to code 71: (setq jus (cdr (assoc 71 (entget ent))))   

2. note that the final justify code is jus + 5. it seems that the first 5 codes are ignored by Mtext for some reason. I don't know why,but bottum line - that is how it's working...      

txtToBlk8.lsp

Edited by aridzv
Link to comment
Share on other sites

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