+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
  1. #1
    Junior Member
    Computer Details
    mhmtlgrr's Computer Details
    Operating System:
    Windows 7
    Computer:
    HP Workstation Z240
    Discipline
    Architectural
    mhmtlgrr's Discipline Details
    Occupation
    Architect
    Discipline
    Architectural
    Using
    AutoCAD 2015
    Join Date
    Jul 2012
    Posts
    11

    AutoCAD Replace text with block and transfer value into attribute

    Registered forum members do not see this ad.

    Dear all,

    I need a lisp routine which basicly performs the action below:

    I have only room number as mtext objects. What I want to achieve is:

    I defined a block with attribute inside named ROOM_NO,
    I want to replace each mtext object with this block while getting the value into the attribute.

    The issue comes from migrating the drawing from Revit to AutoCad. Revit exports the room tags as mtext objects and I need to covert them to proper blocks with attibute. I have over 3000 rooms which is why a lisp routing comes in handy.

    Regards,

    MA

  2. #2
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,085

    Default

    Hi,

    If you are using AutoCAD LT as shown in your profile so you have no luck to run any Lisp codes with it.

  3. #3
    Junior Member
    Computer Details
    mhmtlgrr's Computer Details
    Operating System:
    Windows 7
    Computer:
    HP Workstation Z240
    Discipline
    Architectural
    mhmtlgrr's Discipline Details
    Occupation
    Architect
    Discipline
    Architectural
    Using
    AutoCAD 2015
    Join Date
    Jul 2012
    Posts
    11

    Default

    Dear Tharwat,

    I joined this forum in 2012 and totally missed updating my profile in this period. Thanks for warning.

    I am currently using AutoCad 2015 (not LT) in the office.

  4. #4
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,085

    Default

    No worries.

    Did you create the Attributed Block?
    Then what's the name of this Block?
    Do you have a list of these Room names?
    Is there any of these Mtexts formatted?

  5. #5
    Junior Member
    Computer Details
    mhmtlgrr's Computer Details
    Operating System:
    Windows 7
    Computer:
    HP Workstation Z240
    Discipline
    Architectural
    mhmtlgrr's Discipline Details
    Occupation
    Architect
    Discipline
    Architectural
    Using
    AutoCAD 2015
    Join Date
    Jul 2012
    Posts
    11

    Default

    Let me explain as per your questions:

    Did you create the Attributed Block?
    - Yes.
    Then what's the name of this Block?
    -The block is named as ROOMTAG
    Do you have a list of these Room names?
    -Room numbers are distributed over the DWG
    Is there any of these Mtexts formatted?
    -All room numbers are placed in Mtext objects

    I shared a file with this post. Please check out the file as working drawing.
    Attached Files

  6. #6
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,085

    Default

    Give this a try.
    Code:
    (defun c:Test (/ sel int ent att spc)
      ;; Tharwat - Date: 19.Jun.2017	;;
      (if
        (and
          (or (tblsearch "BLOCK" "ROOMTAG")
              (alert "Attributed Block <ROOMTAG> is not found in drawing <!>")
          )
          (princ "\nSelect Mtexts to be replaced with Attributed Block <ROOMTAG> :")
          (setq sel (ssget "_:L" '((0 . "MTEXT"))))
        )
         (progn
           (defun unformatmtext (string / text str)
             ;;	ASMI - sub-function			;;
             ;; Get string from Formatted Mtext string	;;
             (setq text "")
             (while (/= string "")
               (cond ((wcmatch (strcase (setq str (substr string 1 2)))
                               "\\[\\{}`~]"
                      )
                      (setq string (substr string 3)
                            text   (strcat text str)
                      )
                     )
                     ((wcmatch (substr string 1 1) "[{}]")
                      (setq string (substr string 2))
                     )
                     ((and (wcmatch (strcase (substr string 1 2)) "\\P")
                           (/= (substr string 3 1) " ")
                      )
                      (setq string (substr string 3)
                            text   (strcat text " ")
                      )
                     )
                     ((wcmatch (strcase (substr string 1 2)) "\\[LOP]")
                      (setq string (substr string 3))
                     )
                     ((wcmatch (strcase (substr string 1 2)) "\\[ACFHQTW]")
                      (setq string (substr string
                                           (+ 2 (vl-string-search ";" string))
                                   )
                      )
                     )
                     ((wcmatch (strcase (substr string 1 2)) "\\S")
                      (setq str    (substr string 3 (- (vl-string-search ";" string) 2))
                            text   (strcat text (vl-string-translate "#^\\" " " str))
                            string (substr string (+ 4 (strlen str)))
                      )
                      (print str)
                     )
                     (t
                      (setq text   (strcat text (substr string 1 1))
                            string (substr string 2)
                      )
                     )
               )
             )
             text
           )
           (setq spc
                  (vlax-get (vla-get-activelayout
                              (vla-get-activedocument (vlax-get-acad-object))
                            )
                            'block
                  )
           )
           (repeat (setq int (sslength sel))
             (setq ent (ssname sel (setq int (1- int))))
             (and (setq att (vla-insertblock
                              spc
                              (vlax-3d-point (cdr (assoc 10 (entget ent))))
                              "ROOMTAG"
                              1.0
                              1.0
                              1.0
                              0.
                            )
                  )
                  (vl-some
                    '(lambda (x)
                       (if (eq (strcase (vla-get-tagstring x)) "ROOMNO")
                         (progn (vla-put-textstring
                                  x
                                  (unformatmtext (cdr (assoc 1 (entget ent))))
                                )
                                t
                         )
                       )
                     )
                    (vlax-invoke att 'getattributes)
                  )
                  (entdel ent)
             )
           )
         )
      )
      (princ)
    )(vl-load-com)

  7. #7
    Junior Member
    Computer Details
    mhmtlgrr's Computer Details
    Operating System:
    Windows 7
    Computer:
    HP Workstation Z240
    Discipline
    Architectural
    mhmtlgrr's Discipline Details
    Occupation
    Architect
    Discipline
    Architectural
    Using
    AutoCAD 2015
    Join Date
    Jul 2012
    Posts
    11

    Default

    Dear Tharwat,

    It works like a charm! I really appreciate! You can't know how much time you saved me!

    Hopefully I will have the chance to help you back soon.

    Thank you very much again.

    Regards,

    MA

  8. #8
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,085

    Default

    Quote Originally Posted by mhmtlgrr View Post
    Dear Tharwat,

    It works like a charm! I really appreciate! You can't know how much time you saved me!

    Hopefully I will have the chance to help you back soon.

    Thank you very much again.

    Regards,

    MA
    Great to hear. You are most welcome.

  9. #9
    Forum Newbie
    Using
    Map 3D 2016
    Join Date
    Sep 2016
    Posts
    3

    Smile need to insert in source layer

    I was looking for the same routine. Thank you very much.

    Also i need the block to be inserted in the source layer. Currently its placing in "0" layer. please update this lisp to place in source object layer.



    Thank you
    Nanjappa

  10. #10
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,085

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by nanjac86 View Post
    I was looking for the same routine. Thank you very much.

    Also i need the block to be inserted in the source layer. Currently its placing in "0" layer. please update this lisp to place in source object layer.

    Thank you
    Nanjappa
    Good to hear that.

    Please add the following codes.
    Code:
    (progn (vla-put-layer att (cdr (assoc 8 (entget ent)))) t)
    Before the following codes in the routine.
    Code:
    (entdel ent)
    Like this:
    Code:
    (progn (vla-put-layer att (cdr (assoc 8 (entget ent)))) t)
    (entdel ent)

Similar Threads

  1. How to replace text attribute value using -ATTEDIT regardles of existing value?
    By vernonlee in forum The CUI, Hatches, Linetypes, Scripts & Macros
    Replies: 20
    Last Post: 26th Oct 2016, 04:16 pm
  2. Replace vl-sort with user selection order - Block Attribute Number Sequencing
    By rayg11757 in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 18th Jul 2013, 01:17 am
  3. Block Replacement with Attribute Transfer
    By Unadrafter in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 12th Jul 2010, 06:26 pm
  4. Can any one help me to replace attribute values in Block.
    By shamkumaresan in forum AutoCAD General
    Replies: 10
    Last Post: 2nd Sep 2009, 09:55 pm
  5. Replace old block-attribute with new one
    By Sasolini in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 7th Jun 2007, 02:59 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts