Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Mtext to block data

31 REPLIES 31
SOLVED
Reply
Message 1 of 32
timothy.birdwell
1942 Views, 31 Replies

Mtext to block data

So here is the goal I am looking for. I need a lisp that can select a Mtext, temporarily store each line individually. Then return each line inside an objects data. The command would ask to select an object, then select the data to be transfered. I don't know if this has been done in earlier post, I have been looking. I will attach a test drawing. The block reference already has an OD: which is meant for separate data. The data I need to fill out is Block:Fiber_Ped. Also add longitude and latitude. The following picture will show how the block is set up and what it needs to look like, the data is manually entered at this time. The mtext will stay in the file but as an invisiblelayer, but don't need a function for that.

fiberped.jpg

 

31 REPLIES 31
Message 21 of 32

@ronjonp it was running smooth and now hitting a wall with it. I am trying to understand the code while we are doing this, this is harder to read than c++ lol. Attached will be the image of the problem and a test drawing.

testgonewrong.jpg

Message 22 of 32
ronjonp
in reply to: timothy.birdwell

@timothy.birdwell 

It' not the code it's internal formatting on your MTEXT.

 

(1 . "\\pxt12;PED 51CO3A-1-8R/009\\P\\ptz;BDO4\\PBM2\\PFT(A)\\P110-BM60(1)(1.25)\\P110-BFO48I\\P16-BFO48")

 

 

Do a search for 'stripmtext' and use that to cleanup your text prior to using the code.

 

There is also this excellent function, but we'd have to modify it so the the "\\P" does not get stripped.

 

I've updated my original post to use Lee's unformat function. Definitely test it out.

Message 23 of 32
timothy.birdwell
in reply to: ronjonp

Thank you again, I get the files towards the end. They go through every office coast to coast, and I get to deal with all the random project standards. You have been a real big help.

Message 24 of 32
ronjonp
in reply to: timothy.birdwell


@timothy.birdwell wrote:

Thank you again, I get the files towards the end. They go through every office coast to coast, and I get to deal with all the random project standards. You have been a real big help.


@timothy.birdwell Glad to help .. try out the code in my original post. It cleans up your sample drawing.

ronjonp_0-1670513676602.png

 

Message 25 of 32
timothy.birdwell
in reply to: ronjonp

Wow you went to town on this, what's the best way for me to learn lisp? I'm assuming Lee mac lol. but man I would love to give back to the community the way you helped me out.

 

 

Message 26 of 32
ronjonp
in reply to: timothy.birdwell

Practice. 🙂 Also, don't quote the code over and over .. it makes it hard to find which is the best version. I've made a small change to the original code so use that instead.

 

Lee's site is very informative but also frequenting different forums:

theswamp.org

cadtutor.net

are both great resources as  well.

Message 27 of 32
timothy.birdwell
in reply to: ronjonp

Question for you, Im now trying to grab blocks and insert that property into the fiber_ped, in the fields of Assignment_I....etc. How would I go about changing the end of this code to get the desired effect? 

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-for-combining-multiple-block-attributes-into-a-main-block/td-p/11637019
; an attempt by AlanH Dec 2022

; Sort functions By pbejse forums/autodesk



(defun _n (str / s)
    (setq s (vl-string-right-trim "0123456789" str))
    (list s (atoi (substr str (1+ (strlen s)))))
)
(Defun ThisSortFunc (l)
         (Vl-sort l '(lambda (n m)
                             (setq n (_n (Car n)) m (_n (Car m)))
                       (cond
                         ((< (Car n) (car m)))
                         ((eq (Car n) (car m)) (< (Cadr n) (cadr m)))
                       )
                     )
         )
)
(defun c:wow ( / )
(princ "\n Pick 1 block object for block name ")
(setq ss (ssget "_+.:E:S" '((0 . "INSERT"))))
(if (= ss nil)
(alert "You may not have picked a block please try again")
(progn
(setq blk (vlax-ename->vla-object (ssname ss 0)))
(setq bname (vla-get-name blk))
(if (wcmatch bname "*U#*")
(setq bname (vla-get-effectivename blk))
)
(princ "\nSelect the blocks ")
(setq ss (ssget '((0 . "INSERT"))))
(if (= ss nil)
(alert "No blocks picked will exit")
(progn
(setq lst '())
(repeat (setq x (sslength ss))
(setq lst2 '())
(setq ent (ssname ss (setq x (- x 1))))
(setq blk (vlax-ename->vla-object ent))
(setq blkname (vla-get-name blk))
(if (wcmatch blkname "*U#*")
(setq blkname (vla-get-effectivename blk))
)
(if (= blkname bname)
(progn
(setq atts (vlax-invoke blk 'Getattributes))
(if (= atts nil)
(princ "No Atts")
(progn
(foreach att atts
(setq lst2 (cons (vla-get-textstring att) lst2))
)
(setq odname (ade_odgettables ent))
(setq Stnum (ade_odgetfield ent odname "STREET_NUMBER" 0))
(setq Stname (ade_odgetfield ent odname "STREET_NAME" 0))
(setq state (ade_odgetfield ent odname "STATE" 0))
(setq Pcode (ade_odgetfield ent odname "POSTAL_CODE" 0))
(setq lst (cons (list  (car lst2) (strcat stnum " " stname " " state " " pcode)) lst))
(setq lst (ThisSortFunc lst))
)
)
)
)
)
(setvar 'attreq 0)
(command "-insert" "Fiber_Ped" (getpoint "\nPick insertion point ") 9 9 0)
(setvar 'attreq 1)
(setq len (length lst))
(setq blkatts (vlax-invoke (vlax-ename->vla-object (entlast)) 'Getattributes))
(setq x 0 Y 0)
(repeat (- 12  len)
(vla-put-textstring (nth x blkatts) (strcat (car (nth y lst)) " " (cadr (nth y lst))))
(setq x (1+ x) y (1+ y))
)
)
)
)
)
(princ)
)
(c:wow)

 

 

Message 28 of 32
ronjonp
in reply to: timothy.birdwell

Sorry I can not test this as I do not have 'ade_odgetfield' available.

 

You also have 3 arguments for your second '(if (= ss nil)" statement.

ronjonp_0-1672762527999.png

 

Are you using the VLIDE to troubleshoot this? If not that's one step to becoming a better programmer.

Once you learn to debug your own code the sky is the limit 🙂

 

Message 29 of 32
timothy.birdwell
in reply to: ronjonp

Yes been using Vlide to debug and stepping through. As far as the code goes it recalls the information I need, but it places a new block and insert information at the contents field in the fiber block. Im wanting to not place a fiber bloc, but select it to auto populate the assignment fields with the list. I ran a get ent lisp and was able to pull information out the fiber block. I don't under stand how to grab, ex: (2. "ASSIGNMENT_I") and the new list to combine as a field and value, where the first (2. "ASSIGNMENT_I") is the field, and use the new list to update the value on the block, making it look like 

a3.jpg

Message 30 of 32
ronjonp
in reply to: timothy.birdwell

@timothy.birdwell 

Sorry, I'm not following what you're trying to accomplish. 

Message 31 of 32

PLEASE DO NOT REMOVE ORIGINAL NAME OF AUTHORS OR IF MISSING ADD, that is my code and its posted to your other question re this task.

 

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-for-combining-multiple-block-at...
; an attempt by AlanH Dec 2022

 

There is no need to start another post.

 

If there is a problem with my code let me know.

 

Look at this line

 

(vla-put-textstring (nth x blkatts) (strcat (car (nth y lst)) " " (cadr (nth y lst))))

 

 Had a bracket missing  in your code its there in original code. You can edit what the string is and add the "|"

Message 32 of 32

I apologize about that, I went ahead and corrected it. The reason I removed the brackets on 

(vla-put-textstring (nth x blkatts) (strcat (car (nth y lst)) " " (cadr (nth y lst))))

it was throwing a bad argument type: stingp nil. After removing it worked with out error

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report