Author Topic: How to enter Block definition to dedelte an entity  (Read 4801 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
How to enter Block definition to dedelte an entity
« on: January 16, 2011, 01:34:11 PM »
I am trying to delete a LWpolylines from the existed blocks in a dwg, but something wrong with it .

Would anyone check these codes for me please ?

Code: [Select]
(vl-load-com)
(vlax-for blks
          (vla-get-Blocks
                       (vla-get-ActiveDocument (vlax-get-Acad-Object)))
    (vlax-for i blks
        (if (setq ss
                        (ssget "_X" '((0 . "LWPOLYLINE"))))
  (command "_.erase" ss "")
  (princ "\n No LWpolylines found")
         )
      )
  )
 (vla-regen (vla-get-ActiveDocument   (vlax-get-acad-object)) acAllViewports)



MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: How to enter Block definition to dedelte an entity
« Reply #1 on: January 16, 2011, 01:55:33 PM »
<coded blind> this should work:

Code: [Select]
(vlax-for block (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
    (vlax-for object block
        (if (eq "AcDb2dPolyline" (vla-get-objectname object))
            (vla-delete object)
        )
    )
)

will delete lwpolylines from all blocks, including modelspace, paperspace

bare minimum code / no error trapping: e.g. will get a shovel in the face if the polyline is on a locked layer
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Coder

  • Swamp Rat
  • Posts: 827
Re: How to enter Block definition to delete an entity
« Reply #2 on: January 16, 2011, 02:07:48 PM »
Thanks a lot .

It did not delete any LWpolyline from the block . :-(

and it returns "nil"

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: How to enter Block definition to dedelte an entity
« Reply #3 on: January 16, 2011, 02:08:30 PM »
do a regen then report back  :wink:

what did you expect it to return?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Coder

  • Swamp Rat
  • Posts: 827
Re: How to enter Block definition to dedelte an entity
« Reply #4 on: January 16, 2011, 02:13:37 PM »
I already did regen after implementing these codes .

And I do expect codes to delete the LWpolyline or as you call it "AcDb2dPolyline" . :-)

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: How to enter Block definition to dedelte an entity
« Reply #5 on: January 16, 2011, 02:18:50 PM »
Try:

Code: [Select]
(vlax-for block (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object))))
    (vlax-for object block
        (if (eq "AcDbPolyline" (vla-get-objectname object))
            (vla-delete object)
        )
    )
)

(vla-regen doc acallviewports)


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: How to enter Block definition to dedelte an entity
« Reply #6 on: January 16, 2011, 02:23:11 PM »
Code: [Select]
[quote author=coder link=topic=36695.msg416891#msg416891 date=1295205217]
I already did regen after implementing these codes .

lee's code suggests my algo was proper, so it implies the objects you want to delete in your blocks are not lwpolylines if they are still there after a regen / regenall

And I do expect codes to delete the LWpolyline or as you call it "AcDb2dPolyline" . :-)

wut
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Coder

  • Swamp Rat
  • Posts: 827
Re: How to enter Block definition to dedelte an entity
« Reply #7 on: January 16, 2011, 02:23:40 PM »
Try:
Code: [Select]
(vlax-for block (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object))))
    (vlax-for object block
        (if (eq "AcDbPolyline" (vla-get-objectname object))
            (vla-delete object)
        )
    )
)
(vla-regen doc acallviewports)

Waw that's it .

Thank you so much mr Lee.

And thanks for MP

Appreciated guys

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: How to enter Block definition to dedelte an entity
« Reply #8 on: January 16, 2011, 02:26:26 PM »
oh, I see the error, I should have used "AcDbPolyline" instead of "AcDb2dPolyline"

sorry for the misdirection

so much for coding blind

leaving posts in err intact for thread continuity
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: How to enter Block definition to delete an entity
« Reply #9 on: January 16, 2011, 02:29:37 PM »
and it returns "nil"

Just to clarify: the vla-delete method should return nil.

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: How to enter Block definition to dedelte an entity
« Reply #10 on: January 16, 2011, 02:30:14 PM »
so much for coding blind

Happens to the best of us  :-)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: How to enter Block definition to dedelte an entity
« Reply #11 on: January 16, 2011, 02:36:09 PM »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Coder

  • Swamp Rat
  • Posts: 827
Re: How to enter Block definition to dedelte an entity
« Reply #12 on: January 16, 2011, 02:50:47 PM »
Is it possible to be made with Vanilla  ? :|

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: How to enter Block definition to dedelte an entity
« Reply #13 on: January 16, 2011, 03:25:45 PM »
If by vanilla you mean "not activex based" it's harder, as my recollection is that entdel won't work on entities in block definitions (could be wrong, try it and confirm / refute), so you have to fake it by walking thru each block definition, collect the entities that are not lwpolylines, and then redefine the block with the remaining entities.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: How to enter Block definition to dedelte an entity
« Reply #14 on: January 16, 2011, 03:40:14 PM »
entdel won't work on entities in block definitions, so you have to fake it by walking thru each block definition

Correct  :-)

Messy...

Code: [Select]
(
  (lambda ( / block )
    (while (setq block (tblnext "BLOCK" (null block))) (entmake block)
      (
        (lambda ( block )
          (while block
            (if (not (eq "LWPOLYLINE" (cdr (assoc 0 (entget block)))))
              (entmake (entget block))
            )
            (setq block (entnext block))
          )
          (entmake (list (cons 0 "ENDBLK") (cons 8 "0")))
        )
        (cdr (assoc -2 block))
      )
    )
  )
)