Jump to content

Multiple block editing help


Alistair

Recommended Posts

  • Replies 29
  • Created
  • Last Reply

Top Posters In This Topic

  • Alistair

    10

  • eldon

    9

  • BlackBox

    6

  • irneb

    3

Top Posters In This Topic

Posted Images

Hi Eldon,

 

Unfortunately, due the maximum file size I can upload to the forum, I've had to reduce the number of points I can send through and for some reason as I save it to a previous version of AutoCAD the file size seems to increase. I purged the drawing to get rid of unwanted info but it still comes out at 240KB. I thought I could look at your result and reproduce it in my copy with the 378 points...will this be possible do you think?

 

Thanks,

 

Alistair.

Link to comment
Share on other sites

I am afraid not because of the routine that I run. Post it in whatever version you are running, and I can run it through Drg True View. I can always post back in more than one drawing.

Link to comment
Share on other sites

OK, here they are. I have saved the ID points only, so you will have to insert these drawings at 0,0. I have used a text style PointID and a layer PointID so you won't get muddled up. There were a couple of points at 0,0 in dwg 1, so I deleted those.

 

An Autolisp solution would stand you in good stead for the future, but I am afraid that is beyond my powers.

PointsOnly-2.dwg

PointsOnly-1.dwg

Link to comment
Share on other sites

Eldon,

 

Thank you very much for your help it is much appreciated.

 

All the best from 'sunny Kendal, UK'. That's my next learning curve then...AutoLISP routines!!

 

Cheers, Alistair.

Link to comment
Share on other sites

That clearly lets me off the hook. Although with 300+ blocks, that would need a lisp routine, so it's all in your safe hands now for the lisp. :)

 

The LISP is the easy part... the OP needs a standard block.

 

Renderman, I think I get the jist of your solution and I think this is the thought process I had, without knowing if it was possible in AutoCAD. I would like to understand more about your idea if you could elaborate. For this one-off situation, Eldon's solution appears to be relatively straight forward.

 

Here's the gist:

 

As all of the blocks in the sample drawing you posted have a "BLK*" prefix, I simple make a Selection Set of those blocks. Then stepping through that Selection Set one-at-a-time, I extract the attribute's TagString Property, and TextString value, and store both to a Grouped Pair (TagString . TextString). With all of the attributes cycled, and all values stored, we continue by inserting our new standard block.

 

** Note - I've attached a sample 'standard block' (a very simple one at that), but you really need to determine what is best for your situation. Just be sure to save "TREE-X.dwg" to a location that resides within your Support File Search paths.

 

For example:

 

The block I've attached has each attribute on a separate layer for more control over which data is displayed. You need to format to your liking.

 

Using the EAST, and NORTH values from the stored grouped pairs, I put the newly inserted block at the correct coordinates (using zero for the elevation), and proceed with populating the values of the newly inserted block with the values stored from the original block.

 

Here's the working code:

 

(defun c:FOO ( / *error* ss oLayer blockObj attList oBlock space attVal)
 (princ "\rWorking, please wait... ")
 (vl-load-com)

 (defun *error*  (msg)
   (cond ((not msg))                                                   ; Normal exit
         ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
         ((princ (strcat "\n** Error: " msg " ** "))))                 ; Fatal error, display it
   (and oBlock (vla-delete oBlock))
   (princ))

 ;; Main code  
 (if (setq ss (ssget "_x" '((0 . "INSERT") (2 . "BLK*"))))
   (progn
     ;; Begin undo
     (vla-startundomark
       (cond (*activeDoc*)
             ((setq *activeDoc*
                     (vla-get-activedocument
                       (vlax-get-acad-object))))))

     ;; Layer check
     (if (not (tblsearch "layer" (setq layerName "TREE-X")))
       (progn
         (setq oLayer
                (vla-add (vla-get-layers *activeDoc*) layerName))
         (vla-put-color oLayer 
         (vla-put-description oLayer "Trees-Existing ")))

     ;; Block check
     (if (not (tblsearch "block" "TREE-X"))
       (progn
         (setq oBlock
              (vla-insertBlock
                (cond (space)
                      ((setq space (vla-get-modelspace *activeDoc*))))
                (vlax-3d-point '(0 0 0))
                "TREE-X.dwg"
                1.
                1.
                1.
                0.))
         (vla-delete oBlock)))

     (vlax-for blockObj
               (setq ss (vla-get-activeselectionset *activeDoc*))

       ;; Extract attrib values
       (foreach att  (vlax-invoke blockObj 'getattributes)
         (if (= "AcDbAttribute" (vla-get-objectname att))
           (setq attList
                  (cons (cons (strcase (vla-get-tagstring att))
                              (vla-get-textstring att))
                        attList))))

       ;; Insert new block
       (setq oBlock
              (vla-insertBlock
                (cond (space)
                      ((setq space (vla-get-modelspace *activeDoc*))))
                (vlax-3d-point '(0 0 0))
                "TREE-X"
                1.
                1.
                1.
                0.))
       (vla-move
         oBlock
         (vlax-3d-point '(0 0 0))
         (vlax-3d-point
           (list (atof (cdr (assoc "EAST" attList)))
                 (atof (cdr (assoc "NORTH" attList)))
                 0.)))
       (vla-put-layer oBlock "TREE-X")
       (foreach att  (vlax-invoke oBlock 'getattributes)
         (if
           (/= ""
               (setq attVal
                      (cdr (assoc (vla-get-tagstring att) attList))))
            (vla-put-textstring att attVal)))
       (and attList (setq attList nil))
       (and oBlock (setq oBlock nil))
       [color=green];;(vla-delete blockObj) ;<-[/color][color=green] Uncomment to delete original block[/color]
       )
     (vla-delete ss)
     (vla-endundomark *activeDoc*))
   (prompt "\n**  Nothing selected ** "))
 (princ))

 

Additionally, I've incorporated a layer check, and this routine places all newly inserted blocks onto that layer "TREE-X" for example purposes, and to perhaps make them (the resultant blocks) a bit easier for you to work with.

 

Hope this helps!

TREE-X.dwg

Link to comment
Share on other sites

Hello Renderman,

 

This is great thanks. It's at the limit of my current AutoCAD knowledge, so I'll have to spend a bit of time working out what you have created for me, but I get the basic idea. I may need to come back to you to query some points if I get stuck.

 

Many thanks,

 

Alistair :)

Link to comment
Share on other sites

This is great thanks.

 

You're welcome. :)

 

Someone may come along with a better way, but that is what first came to mind for me, so I'm glad it helps.

 

I'll have to spend a bit of time working out what you have created for me, but I get the basic idea. I may need to come back to you to query some points if I get stuck.

 

That's what these forums are for. :wink:

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