Jump to content

Recommended Posts

Posted

Since a block is really just a group of Enames, is it possible to explode a block, gather all the entities that were in the block, and rebuild the block later by adding all those entities back into a selection set and re-blocking (with the original insertionpoint, rotation, and all that of course).

 

I want to make a routine that moves blocks into a grid, adds attributes for the specific details of each block, and explodes everything down to regular geometry (saving each block name and entity set) so that I can edit several blocks at one time, then go back through the grid and re-block all items back together, and place them in their original spots.

 

I know it's possible to use the block collection to find all entity names within a block and that might be the ticket. Just wondering if this is even possible or feasible.

 

thanks,

 

-ArgV

Posted

possible but fairly complicated. I have done similar things. Where are you at with this app?

Posted

Yes, this is possible.

 

I think it would be best to proceed with Visual LISP methods on this, as you will find it easier to manipulate the entities.

 

For example, you modify entities within a block using the block object in the block collection and iterating through the object using vlax-for.

 

If you need some help on this, I'd be more than happy to lend a hand :)

 

Lee

Posted
Yes, this is possible.

 

I think it would be best to proceed with Visual LISP methods on this, as you will find it easier to manipulate the entities.

 

For example, you modify entities within a block using the block object in the block collection and iterating through the object using vlax-for.

 

If you need some help on this, I'd be more than happy to lend a hand :)

 

Lee

 

Well thanks! I never ask anyone to take time to write code, I usually just have questions on "How to do this" or whatever. Anyways, This is going to be pretty complicated because I also want to be able to process an unknown amount of nested blocks if needed (or, at least 3 levels deep).

 

The basics pseudo-code for this is kinda like:

  • Get selection set of blocks to repair.

  • build grid depending on number of blocks selected (and largest bounding box?)
  • move blocks to middle of each grid square
  • get name of block, add as attribute to square
  • explode block....
  • get pieces.. make selection set for re-blocking.

Well, it gets weird from here.. You need the insertion point, rotations, etc to add as attributes and put inside the square for re-blocking purposes. Haven't gotten much past that. Make a selection set after each explosion.. OR, find each block and get the selection set by iterating through the block collection.

 

This would be a killer application if it worked right!

 

I have some stuff written, but I'm a newbie and it's probably not worthy of posting.. it's kinda.. rough around the edges I guess. :)

 

If you have spare time, and think this is a good waste of it, feel free. :)

 

thanks,

 

ArgV

 

Ok, I lied. Here is the first part of the code I made, which makes the grid, moves all the blocks, puts in some generic attributes.

 

(defun C:makeGrid (/ ss cntr att1 att2 att3 x y z ss_item object bb ll ur midx midy mid newSpot)



(setq doc (vla-get-activedocument (vlax-get-acad-object))
      model (vla-get-modelspace doc))
(vla-startundomark doc)
(setvar "osmode" 0)


(command "view" "o" "top")
(setq ss (ssget (list (cons 0 "insert")(cons 410 "model")))
      oldos (getvar "osmode"))
(setq cntr 0)
(setq pt (getpoint "\nSelect point to start grid: "))
 
(setq x (car pt)
     y (cadr pt)
     z 0.0)
 
(setq gridSize (fix (sqrt (sslength ss))))
(if (rem (sqrt (sslength ss)))
 (setq gridSize (+ 1 gridSize))
 )
(vla-add (vla-get-layers doc) "GRID")
(command "clayer" "GRID")
(command "rectang" (list x y z) (list (+ x 150.) (+ y 150.) 0.))
(command "-array" "l" "" "r" gridSize gridSize "150" "150")



(while (< cntr (sslength ss))
 (setq ss_item (ssname ss cntr)
   
       object (vlax-ename->vla-object ss_item)
   insPoint  (cdr (assoc 10 (entget ss_item)))
       bb (vla-getboundingbox object 'pt1 'pt2)
       ll (vlax-safearray->list pt1)
       ur (vlax-safearray->list pt2)
       midx (+ (car ll) (/ (- (car ur)(car ll))2))
       midy (+ (cadr ur) (/ (- (cadr ll)(cadr ur))2))
       mid (list midx midy 0.0)
       name (vla-get-name object)
       )
  (if
    (and
      (= (vla-get-isdynamicblock object) :vlax-true)
      (vlax-property-available-p object "effectivename"))
    (setq name (vla-get-effectivename object))
    )
 
 (setq newSpot (list (+ x 75) (+ y 75) z);Find middle of grid square 
   att1 (list (+ x 75)(+ y 12) z)
   att7 (list (+ x 75)(+ y 9) z)
   att8 (list (+ x 75)(+ y 6) z))
  
  ;add attributes for name and such...
  (if
    name
    (progn
    (setq a1 (vla-addattribute model 3.0 acattributemodeconstant "Part #" (vlax-make-variant (vlax-3d-point att1)) "1" name))
    (setq a2 (vla-addattribute model 3.0 acAttributeModeInvisible  "Group sorting" (vlax-make-variant (vlax-3d-point att7)) "7" "Group"))
    (setq a3 (vla-addattribute model 3.0 acAttributeModeInvisible  "Area sorting" (vlax-make-variant (vlax-3d-point att8)) "8" "Area"))
    )
   )
(vla-add (vla-get-layers doc) "TEXT")
  (vla-put-layer a1 "TEXT")
  (vla-put-layer a2 "TEXT")
  (vla-put-layer a3 "TEXT")
  
(command "move" ss_item "" mid newSpot);move top to middle of a grid square..

(setq cntr (+ cntr 1))
 (if
   (< y (+ (* (- gridSize 1) 150) (cadr pt)))
  (setq y (+ y 150))
  (setq x (+ x 150)
        y (cadr pt)))
 )
(setvar "osmode" oldos)
(vla-endundomark doc)
)




(defun *error* (msg)
(princ msg)
(setvar "osmode" oldos)
)
(princ "Type MakeGrid to run")

Posted

OK, this is quite a lot of work, but it can be done.

 

btw, is this a purely 2D problem?

 

I understand about making the grid and positioning the block, but I don't understand the attributes and exploding of the block and re-blocking - are you trying to make one block from many?

 

Lee

Posted
OK, this is quite a lot of work, but it can be done.

 

btw, is this a purely 2D problem?

 

I understand about making the grid and positioning the block, but I don't understand the attributes and exploding of the block and re-blocking - are you trying to make one block from many?

 

Lee

 

This is a 2D problem. There are dynamic blocks nested as well.

 

The attributes we use for space planning purposes, and the name is a large attribute that has the name. This is for a furniture company, and we use several blocks for legs, grommets, keyboard assemblies, drill holes, etc, and then block the whole thing as one block for programming and CNC machining purposes, space planning, etc.. (it is ONE table after all). ( and our nesting software runs off autocad). So making the table machine ready requires stripping all the blocks off and getting it down to just the needed stuff according to the order.

 

So, I guess the answer is "yes" we make one block from many. When we have to fix these blocks, it's a pain doing it one block at a time, so I want to make this program (actually will probably be two programs - one to move blocks to grid, and one to move them back into position) to make fixing a multitude of nested blocks WAYYYYYYYYY faster and easier (and less chance of error). Alot of times we move a drill hole or something, and we have to do it to EVERY top (there are thousands). This way you could just get all those holes, move it on all the tops at once, and re-block them back.

 

I hope that makes any sense. :) I know its a pain, so if you want to just help me with some of the individual elements that would be great. For now my problem is "How do I re-make the block and put it back into the exact same position it was?"

 

thanks, Lee.

 

-ArgV

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