Remove object from blocks (No Deleted)

Remove object from blocks (No Deleted)

neam
Collaborator Collaborator
1,173 Views
18 Replies
Message 1 of 19

Remove object from blocks (No Deleted)

neam
Collaborator
Collaborator

Hi everyone:

Is it possible to remove (no delete) an object (e.g. all text that are in layer "Cement_Total") from all blocks?

0 Likes
Accepted solutions (2)
1,174 Views
18 Replies
Replies (18)
Message 2 of 19

komondormrex
Mentor
Mentor

hey,

you can switch them off

(defun c:twrblkpropchg ( / blc blk doc idx lst sel )
   (if (setq sel (ssget "_X" '((0 . "INSERT"))))
       (progn
           (setq doc (vla-get-activedocument (vlax-get-acad-object))
                 blc (vla-get-blocks doc)
           )
           (repeat (setq idx (sslength sel))
               (setq idx (1- idx)
                     blk (vla-get-effectivename (vlax-ename->vla-object (ssname sel idx)))
               )
                       (vlax-for obj (vla-item blc blk)
                           (if (and (wcmatch (strcase (vla-get-Objectname obj)) "*TEXT") (= (vla-get-layer obj) "Cement_Total"))
                               (vlax-put obj 'visible 0); 0 - off, 1 - on
                           )
                       )
           )
           (vla-regen doc acallviewports)
       )
   )
   (princ)
)
(vl-load-com) (princ)
Message 3 of 19

ronjonp
Mentor
Mentor

@neam Why don't you just freeze 'Cement_Total' layer? There does not seem to be anything else on that layer but the text.

Message 4 of 19

paullimapa
Mentor
Mentor

Change the Layer "Cement_Total" status to No Plot


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 19

neam
Collaborator
Collaborator

Thankful for reply.

I wanted to know if it is possible to do something like the Refedit (Remove from working set) command with the help of Lisp. Because I wanted to use Cement_Total information elsewhere (without exploding them or making them invisible).

0 Likes
Message 6 of 19

neam
Collaborator
Collaborator

Thankful for reply.

I wanted to know if it is possible to do something like the Refedit (Remove from working set) command with the help of Lisp. Because I wanted to use Cement_Total information elsewhere (without exploding them or making them invisible).

0 Likes
Message 7 of 19

neam
Collaborator
Collaborator

Thankful for reply.

I wanted to know if it is possible to do something like the Refedit (Remove from working set) command with the help of Lisp. Because I wanted to use Cement_Total information elsewhere (without exploding them or making them invisible).

But with the search I made on Google and your guidance.
It seems that this is not possible.

 

0 Likes
Message 8 of 19

neam
Collaborator
Collaborator

for example:

0 Likes
Message 9 of 19

Kent1Cooper
Consultant
Consultant

@neam wrote:

.... I wanted to know if it is possible to do something like the Refedit (Remove from working set) ....


Would there ever be more than one insertion of the same Block name?  If so, REFEDITING it [whether or not that can be done with AutoLisp] to remove that Text would remove it from all such insertions, and only the one at the insertion where the RefEditing was done will remain as an independent Text object not nested in a Block.

Kent Cooper, AIA
0 Likes
Message 10 of 19

neam
Collaborator
Collaborator

Dear Kent thankful for your reply
As you can see in the last attached file.
There are more than 600 blocks with different names on the map.
In all of them, text: CT=123... is common in layer: Cement_Total.

I would be grateful if you could help me further.

0 Likes
Message 11 of 19

Kent1Cooper
Consultant
Consultant
Accepted solution

Well, this is weird.  It has to be done with REFEDIT if you want the Text to remain in the drawing.  But REFEDIT is very finicky about how you select the Block.  You can't just give it an entity name, but it wants a pick.  I tried having it select by the insertion point, where there always seems to be something drawn to pick on, but you have a lot with coinciding insertion points, so it was something seeing the wrong one.  So I tried Isolating each one.  That works for over a hundred of them, but it hangs up when it gets to the Block named Bcement1120, asking again for selection.  I don't see anything about that one that's different from others in a way that should cause this.  It even leaves the drawing in a weird state regarding object selection and highlighting.  I tried turning off Undo recording, I tried freezing the "freez" Layer just in case, I tried getting rid of that particular Block but it just hangs up on the next one.  In case you or anyone wants to try whether the same happens for them, here's the latest iteration:

 

(defun C:UNCT ; = Un-Nest Cement Text
  (/ ss n blk)
  (if (setq ss (ssget "_A" '((0 . "INSERT") (2 . "Bcement*"))))
    (progn ; then
      (command
        "_.layer" "_thaw" "*" "_on" "*" ""
        "_.regen"
      ); command
      (repeat (setq n (sslength ss)); then
        (setq blk (ssname ss (setq n (1- n))))
        (command
          "_.isolateobjects" blk ""
          "_.-refedit"
            (getpropertyvalue blk "Position")
            "_ok" "_all" "_no"
            "_refset" "_remove" (ssget "_A" '((0 . "TEXT") (8 . "Cement_Total") (1 . "CT=*"))) ""
          "_.refclose" "_save"
          "_.unisolateobjects"
        ); command
      ); repeat
    ); progn
  ); if
  (prin1)
)

 

 

Kent Cooper, AIA
Message 12 of 19

ronjonp
Mentor
Mentor

@neam wrote:

Thankful for reply.

I wanted to know if it is possible to do something like the Refedit (Remove from working set) command with the help of Lisp. Because I wanted to use Cement_Total information elsewhere (without exploding them or making them invisible).

But with the search I made on Google and your guidance.
It seems that this is not possible.

 


So if you don't want the layer frozen or the text made invisible then what do you gain by storing this information elsewhere to use it later? I'm confused. 🤔

0 Likes
Message 13 of 19

neam
Collaborator
Collaborator

Dear Kenet thank you so much.

Thank you for taking the time to solve my problem🙏🙏

 

0 Likes
Message 14 of 19

neam
Collaborator
Collaborator

Dear ronjonp:

I am very sorry that I could not express my meaning properly.
I find that the easiest way to do this is to explode the blocks and extract the cement amount information.
During the construction of the dam, we need to insulate the dam construction site by injecting diluted cement at different depths and with pressure.

And the number of these injections can be up to 6000 in total.

And I wanted to use the Refedit function in Lisp, which I did not know, and I raised it in the forum.

0 Likes
Message 15 of 19

ronjonp
Mentor
Mentor
Accepted solution

@neam wrote:

Dear ronjonp:

I am very sorry that I could not express my meaning properly.
I find that the easiest way to do this is to explode the blocks and extract the cement amount information.
During the construction of the dam, we need to insulate the dam construction site by injecting diluted cement at different depths and with pressure.

And the number of these injections can be up to 6000 in total.

And I wanted to use the Refedit function in Lisp, which I did not know, and I raised it in the forum.


@neam No worries. Here's another way to tally those numbers without isolating them.

 

 

(defun c:foo (/ b r s)
  (cond	((setq s (ssget '((0 . "INSERT") (2 . "Bcement*"))))
	 (setq b (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
	 (setq r 0)
	 (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	   (vlax-for a (vla-item b (cdr (assoc 2 (entget e))))
	     (if (and (= "AcDbText" (vla-get-objectname a)) (= "Cement_Total" (vla-get-layer a)))
	       (progn (print (vla-get-textstring a))
		      (setq r (+ r (atof (substr (vla-get-textstring a) 4))))
	       )
	     )
	   )
	 )
	 (alert (vl-princ-to-string r))
	)
  )
  (princ)
)

 

 

Message 16 of 19

neam
Collaborator
Collaborator

Thank you again. I hope that I can benefit from your guidance and expertise in the future.

0 Likes
Message 17 of 19

devitg
Advisor
Advisor

post twice 

 

 

0 Likes
Message 18 of 19

devitg
Advisor
Advisor

@neam Please give it a try, it work with your TMPL_Section 1.dwg

 

0 Likes
Message 19 of 19

neam
Collaborator
Collaborator

Thank you for your attention.
Your code is also a solution, I will use it too.

0 Likes