Strange Block Insertion Issue

When I get a background (in DXF format) from anyone having a non-PC non-Autocad 'cad' package (ie: MAC user) and I create the DWG file, you end up
getting lots of blocks, etc. But this because of the DXF, all the blocks are hard coded with linetypes, colours, layers. Which I don't like. So...
I've a LISP routine to search through the data base to take each block one at a time and:
Change Linetype:    bylayer Change Colour:        bylayer Change Layer:        0 (zero)
Then it redefines the block (using the blocks original insert point).
BUT, here is what happens... when the block is redefined, the block physically is located in a different location on the drawing... even though the insert point IS correct.
I've looked at all the Setvar's, properties, Osnaps, USC, elevations, etc. But can't see anything weird.
Even if I cut/paste one of his blocks on a new drawing, the same thing will happen.
NOW... If I manually explode his block, change the properties, then redefine the block, it is OK. This is using the popup BLOCK menu.
IF I manually define the block using the -block command (ie: no menu), and then manually insert the file ( -insert ), the same weird insert happens.
Anyone KNOW what the hell is going on? It's only with these MAC DXF files that this seems to happen to.
Thanks in advance.
Bruce
Add pictures here
βœ–
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
I suggest that you post a drawing, so we can have a look, and maybe a solution.....
"Mr. B" a ιcrit :

Add pictures here
βœ–
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Okay... here is a 'section' of the drawing in question (one of many). And I've attached a quick LSP file (X.lsp) to show you how the redefining of the block goes strange.
The LSP file gets the current block insert point. Explodes the block and changes the block properties (line type, colour, etc). Then redefines the exploded enties using the original block name and insert point (-block).
Then attempts to insert the block in the SAME insert point (inspt variable). But you'll see it inserts the block in a different location... EVEN though the insert point IS correct.
Something happens during the redefining.
You can do this manually and get the same results as long as you do NOT use the popup Block window. (-block and -insert). IF you DO use the popups, then things are OK. But with hundreds of blocks... alas, not an option.
Regards,
Bruce
Add pictures here
βœ–
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Okay... here is a 'section' of the drawing in question (one of many). And I've attached a quick LSP file (X.lsp) to show you how the redefining of the block goes strange.
The LSP file gets the current block insert point. Explodes the block and changes the block properties (line type, colour, etc). Then redefines the exploded enties using the original block name and insert point (-block).
Then attempts to insert the block in the SAME insert point (inspt variable). But you'll see it inserts the block in a different location... EVEN though the insert point IS correct.
Something happens during the redefining.
You can do this manually and get the same results as long as you do NOT use the popup Block window. (-block and -insert). IF you DO use the popups, then things are OK. But with hundreds of blocks... alas, not an option.
Regards,
Bruce PK
Add pictures here
βœ–
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Well... that didn't work (:
I've a small ZIP file I've tried to attached. But my Server doesn't like it :(
Unless you want me to email you this zip file... then alas.
Bruce
Add pictures here
βœ–
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Bruce, Feel free to email these to me and I will take a look, provided you are NOT using AC2004. But as an aside, rather than exploding/redefining/re-inserting all these blocks, why not change the data that needs to be changed in the block definition itself?
Jeff
wrote:

it
Add pictures here
βœ–
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

I'm using AC2002 LT.

'Cause I HATE it when people 'force' linetypes and colours when I use them as backgrounds (ie: I like to be able to control colours, etc.).
Regards,
Bruce
Add pictures here
βœ–
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
The weird behavior is because of the conversion.....try this Lisp instead
(defun C:X ( / ) (setvar "cmdecho" 0) (setq FirstBlockDefinition (tblnext "BLOCK" t)) (while FirstBlockDefinition (setq Bname (cdr (assoc 2 FirstBlockDefinition))) (setq Def (tblobjname "BLOCK" Bname)) (setq NextItem (entnext Def)) (while NextItem (setq DxfCode (entget NextItem)) (setq DxfCode (subst (cons 62 256) (assoc 62 DxfCode) DxfCode)) (setq DxfCode (subst (cons 6 "bylayer") (assoc 6 DxfCode) DxfCode)) (setq DxfCode (subst (cons 8 "0") (assoc 8 DxfCode) DxfCode)) (entmod DxfCode) (setq NextItem (entnext NextItem)) ) (entupd def) (setq FirstBlockDefinition (tblnext "BLOCK")) ) (princ) )
"Mr. B" a ιcrit :

Add pictures here
βœ–
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Yeah... it'd be nice to know 'why'...

Verrryy nice and slick. The only thing needed was to add a 'regen' command at the end.
Thanks Muchly. I'm going to modify my original LSP file with this.
Regards,
Bruce
Add pictures here
βœ–
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

at
They this Lisp code - I can't remember where I found it from originally:
Matthew
__________________________________
; NUKE.LSP redefines all objects in a block on layer 0, with color and linetype ; set to BYLAYER. NUKED blocks will then take on the properties of the layer ; that they are inserted on. The routine works by modifing objects in the block table, ; so the blocks never have to be exploded. ; ; The global method redefines ALL objects in every block in the current drawing, ; except dimensions, hatching or xrefs, even if they are on a layer that is ; frozen or turned off. ; ; The select method redefines blocks selected with any standard selection method, ; as well as any blocks nested in the selected block(s).
(defun To-0( BLCK / BNAME BLIST E EDATA SPIN TMP )
;;; Prints a pinwheel on the command line (defun Spin ( ) (setq SYM (cond ((= SYM nil) "-") ((= SYM "-") "\\") ((= SYM "\\") "|") ((= SYM "|") "/") ((= SYM "/") "-") ) ) (princ (strcat "\rScanning... " SYM " ")) );end spin
(if (=(type BLCK)(read "LIST"))(setq TMP(car BLCK) BLIST(cdr BLCK) BLCK TMP TMP nil)) (setq BLCK(tblsearch "BLOCK" BLCK)) (if (and (/=(logand(cdr(assoc 70 BLCK))1)1) ;skips annomyous blocks (/= (logand(cdr(assoc 70 BLCK))4)4) ;skips xrefs );and (progn (setq E (cdr (assoc -2 BLCK))) (while E (if (=(cdr(assoc 0 (entget E))) "INSERT") ;If the object is a block (progn (setq BNAME(cdr(assoc 2(entget E)))) ;save the name to a list (if (not (member BNAME BLIST)) (if (not BLIST)(setq BLIST (list BNAME)) ;create the list if it doesn't exist (setq BLIST(append BLIST(list BNAME))) );if );if );progn );if (setq EDATA (entget E)) (if(assoc 62 EDATA) ;Resets object color to BYLAYER if it isn't. (setq EDATA(subst(cons 62 256)(assoc 62 EDATA)EDATA)) );if (if(assoc 6 EDATA) ;Resets object linetype to BYLAYER if it isn't. (setq EDATA(subst(cons 6 "BYLAYER")(assoc 6 EDATA)EDATA)) );if (setq EDATA(subst (cons 8 "0")(assoc 8 EDATA)EDATA));changes layer to 0 (entmod EDATA);updates entity (setq E (entnext E));get next enitiy, nil if end of block (Spin) );end while E );progn );if BLIST; returns names of any nested blocks );defun
(defun C:NUKE( / BLK_NM CHOICE E EDATA IDX PK_BLK SS) (command "._undo" "m") (setq CHOICE "S") (initget "G S") (setq CHOICE(getkword (strcat "\n<G>lobal or <S>elect block: <" CHOICE "> "))) (if(not CHOICE)(setq CHOICE "S")) (if (= (strcase CHOICE) "G") ;global nuke (while (setq BLK_NM(tblnext "BLOCK" (null BLK_NM))) (TO-0 (cdr(assoc 2 BLK_NM))) );while ;nuke selected block (progn (prompt "\nSelect Block(s) to Nuke: ") (setq SS(ssget '((0 . "INSERT")))) (setq IDX 0) (repeat (sslength SS) (setq BLK(cdr(assoc 2 (entget(ssname SS IDX))))) (cond (PK_BLK (setq PK_BLK(append PK_BLK (list BLK)))) (T (setq PK_BLK(list BLK))) );cond (setq IDX(1+ IDX)) );repeat (while PK_BLK (setq PK_BLK(To-0 PK_BLK)) );while );progn );if (command "._regen") (princ "\rFinished ") (princ) );defun (princ)
Add pictures here
βœ–
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
wrote:

Hmmm... Interesting... Works just as well.... Thanks!
Bruce
Add pictures here
βœ–
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.