Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

remove xref or block

15 REPLIES 15
Reply
Message 1 of 16
Anonymous
490 Views, 15 Replies

remove xref or block

I have this code, when opening a dwg its suppose to find the format, for
example, with the name of "fmta1 or fmta1r14" and replace it with a format
called "fmta12k6".
However im trying to modify it to where if its an xref with the names above,
to detach it, purge it and then insert the block of "fmta2k6" but its if its
a block with those names to just redefine it to the format "fmta2k6"
i have multiple formats that have different names as you see in the code
can anyone help me out on how to get to what im after?
if i want to just detach and purgethe xref and i remove the redefine command
it works good
and vice versa however i would like to make it work no matter what the
circumstances are

any help is greatly appreciated

(SETQ SSB (SSGET "x"
(LIST
(CONS 2 "*FMT*")
(cons 10 '(0.0 0.0 0.0))

)
)
)
(SETQ DS (GETVAR "DIMSCALE"))
(setq ss (ssget "X" (list (cons 0 "INSERT"))))
(setq C 0)
(repeat (sslength ss)
(setq entity (ssname ss C))
(setq elist (entget entity))
(setq blockname (strcase (cdr (assoc 2 elist))))
(setq blockcheck (substr blockname 1 5))
(setq fmt (strcat blockcheck "2K6"))
(if (or (= blockname "FMTA1R14")
(= blockname "FMTA1")
(= blockname "FMTB1R14")
(= blockname "FMTB1")
(= blockname "FMTC1R14")
(= blockname "FMTC1")
(= blockname "FMTM1R14")
(= blockname "FMTM1")
(= blockname "FMTS1R14")
(= blockname "FMTS1")
(= blockname "FMTW1R14")
(= blockname "FMTW1")
)
(progn
(command "-XREF" "d" blockname)
(command "-purge" "b" blockname "n")
(command "-insert"(strcat blockname "=" fmt))
(command)
(command "-insert" fmt "0,0" ds ds "0")

)

)



(setq C (+ C 1))
)
15 REPLIES 15
Message 2 of 16
Anonymous
in reply to: Anonymous

Add this function:
(defun is_xref (name / ename data)
(and name
(setq ename (tblobjname "block" name))
(setq data (entget ename))
(= 4 (logand 4 (cdr (assoc 70 data))))
)
)

Then:

(progn
(if (is_xref blockname)
(command "-XREF" "d" blockname)
); if
(command "-purge" "b" blockname "n")
(command "-insert"(strcat blockname "=" fmt))
(command)
(command "-insert" fmt "0,0" ds ds "0")

Bob
Message 3 of 16
Anonymous
in reply to: Anonymous

Bob,
Where am I adding the first part?


wrote in message news:5782187@discussion.autodesk.com...
Add this function:
(defun is_xref (name / ename data)
(and name
(setq ename (tblobjname "block" name))
(setq data (entget ename))
(= 4 (logand 4 (cdr (assoc 70 data))))
)
)

Then:

(progn
(if (is_xref blockname)
(command "-XREF" "d" blockname)
); if
(command "-purge" "b" blockname "n")
(command "-insert"(strcat blockname "=" fmt))
(command)
(command "-insert" fmt "0,0" ds ds "0")

Bob
Message 4 of 16
Anonymous
in reply to: Anonymous

well i realized where it goes but it doesnt work
thanks for the help anyway



wrote in message news:5782288@discussion.autodesk.com...
Bob,
Where am I adding the first part?


wrote in message news:5782187@discussion.autodesk.com...
Add this function:
(defun is_xref (name / ename data)
(and name
(setq ename (tblobjname "block" name))
(setq data (entget ename))
(= 4 (logand 4 (cdr (assoc 70 data))))
)
)

Then:

(progn
(if (is_xref blockname)
(command "-XREF" "d" blockname)
); if
(command "-purge" "b" blockname "n")
(command "-insert"(strcat blockname "=" fmt))
(command)
(command "-insert" fmt "0,0" ds ds "0")

Bob
Message 5 of 16
Anonymous
in reply to: Anonymous

i guess it helps to say why it dont work
when its an xref it doesnt do anything
and goes right to trying to redefine the first block in the block list
instead of the block im after




wrote in message news:5782334@discussion.autodesk.com...
well i realized where it goes but it doesnt work
thanks for the help anyway



wrote in message news:5782288@discussion.autodesk.com...
Bob,
Where am I adding the first part?


wrote in message news:5782187@discussion.autodesk.com...
Add this function:
(defun is_xref (name / ename data)
(and name
(setq ename (tblobjname "block" name))
(setq data (entget ename))
(= 4 (logand 4 (cdr (assoc 70 data))))
)
)

Then:

(progn
(if (is_xref blockname)
(command "-XREF" "d" blockname)
); if
(command "-purge" "b" blockname "n")
(command "-insert"(strcat blockname "=" fmt))
(command)
(command "-insert" fmt "0,0" ds ds "0")

Bob
Message 6 of 16
Anonymous
in reply to: Anonymous

I might be helpful if you specify exactly what you want
it to do.
Case IS Xref ..... do what ?
Case IS NOT Xref .... do what ?

Bob
Message 7 of 16
Anonymous
in reply to: Anonymous

if its an xref (detach it, purge it and insert as a block)
(command "-XREF" "d" blockname)
(command "-purge" "b" blockname "n")
(command "-insert" fmt "0,0" ds ds "0")

if its a block (redefine it)
(command "-insert"(block=block))
(command)


wrote in message news:5782457@discussion.autodesk.com...
I might be helpful if you specify exactly what you want
it to do.
Case IS Xref ..... do what ?
Case IS NOT Xref .... do what ?

Bob
Message 8 of 16
Anonymous
in reply to: Anonymous

In that case, make your 'change' loop look like:

.......
(progn
(if (is_xref blockname)
(progn
(command "-XREF" "d" blockname)
(command "-purge" "b" blockname "n")
(command "-insert" fmt "0,0" ds ds "0")
); progn
); if
(if (not (is_xref blockname))
(progn
(command "-insert"(strcat blockname "=" fmt))
(command)
); progn
); if
.......

Bob
Message 9 of 16
Anonymous
in reply to: Anonymous

sorry still not working
the code below returns "22" in the command line


(SETQ DS (GETVAR "DIMSCALE"))
(SETQ SS (SSGET "x"
(LIST
(CONS 2 "*FMT*")
(cons 10 '(0.0 0.0 0.0))

)
)
)

(setq ss (ssget "X" (list (cons 0 "INSERT"))))
(setq C 0)
(repeat (sslength ss)
(setq entity (ssname ss C))
(setq elist (entget entity))
(setq blockname (strcase (cdr (assoc 2 elist))))
(setq blockcheck (substr blockname 1 5))
(setq fmt (strcat blockcheck "2K6"))
(defun is_xref (name / ename data)
(and name
(setq ename (tblobjname "block" name))
(setq data (entget ename))
(= 4 (logand 4 (cdr (assoc 70 data))))
)
)
(if (or (= blockname "FMTA1R14")
(= blockname "FMTA1")
(= blockname "FMTB1R14")
(= blockname "FMTB1")
(= blockname "FMTC1R14")
(= blockname "FMTC1")
(= blockname "FMTM1R14")
(= blockname "FMTM1")
(= blockname "FMTS1R14")
(= blockname "FMTS1")
(= blockname "FMTW1R14")
(= blockname "FMTW1")
)
(progn
(if (is_xref fmtx)
(progn
(command "-XREF" "d" blockname)
(command "-purge" "b" blockname "n")
(command "-insert" fmt "0,0" ds ds "0")
); progn
); if
(if (not (is_xref blockname))
(progn
(command "-insert"(strcat blockname "=" fmt))
(command)
); progn
); if


)
)

(setq C (+ C 1))
)


wrote in message news:5782644@discussion.autodesk.com...
In that case, make your 'change' loop look like:

.......
(progn
(if (is_xref blockname)
(progn
(command "-XREF" "d" blockname)
(command "-purge" "b" blockname "n")
(command "-insert" fmt "0,0" ds ds "0")
); progn
); if
(if (not (is_xref blockname))
(progn
(command "-insert"(strcat blockname "=" fmt))
(command)
); progn
); if
.......

Bob
Message 10 of 16
Anonymous
in reply to: Anonymous

i take that back, it partially works (typo in the code)
it works with the xref
it doesnt redefine an old block to the new block


wrote in message news:5782712@discussion.autodesk.com...
sorry still not working
the code below returns "22" in the command line


(SETQ DS (GETVAR "DIMSCALE"))
(SETQ SS (SSGET "x"
(LIST
(CONS 2 "*FMT*")
(cons 10 '(0.0 0.0 0.0))

)
)
)

(setq ss (ssget "X" (list (cons 0 "INSERT"))))
(setq C 0)
(repeat (sslength ss)
(setq entity (ssname ss C))
(setq elist (entget entity))
(setq blockname (strcase (cdr (assoc 2 elist))))
(setq blockcheck (substr blockname 1 5))
(setq fmt (strcat blockcheck "2K6"))
(defun is_xref (name / ename data)
(and name
(setq ename (tblobjname "block" name))
(setq data (entget ename))
(= 4 (logand 4 (cdr (assoc 70 data))))
)
)
(if (or (= blockname "FMTA1R14")
(= blockname "FMTA1")
(= blockname "FMTB1R14")
(= blockname "FMTB1")
(= blockname "FMTC1R14")
(= blockname "FMTC1")
(= blockname "FMTM1R14")
(= blockname "FMTM1")
(= blockname "FMTS1R14")
(= blockname "FMTS1")
(= blockname "FMTW1R14")
(= blockname "FMTW1")
)
(progn
(if (is_xref fmtx)
(progn
(command "-XREF" "d" blockname)
(command "-purge" "b" blockname "n")
(command "-insert" fmt "0,0" ds ds "0")
); progn
); if
(if (not (is_xref blockname))
(progn
(command "-insert"(strcat blockname "=" fmt))
(command)
); progn
); if


)
)

(setq C (+ C 1))
)


wrote in message news:5782644@discussion.autodesk.com...
In that case, make your 'change' loop look like:

.......
(progn
(if (is_xref blockname)
(progn
(command "-XREF" "d" blockname)
(command "-purge" "b" blockname "n")
(command "-insert" fmt "0,0" ds ds "0")
); progn
); if
(if (not (is_xref blockname))
(progn
(command "-insert"(strcat blockname "=" fmt))
(command)
); progn
); if
.......

Bob
Message 11 of 16
Anonymous
in reply to: Anonymous

Move the (defun is_xref .. function way up-top, before anything else.. and
this line:
(if (is_xref fmtx)
has variable fmtx .. which I don't see defined.
Change it to:
(if (is_xref blockname)

Bob
Message 12 of 16
Anonymous
in reply to: Anonymous

i realized the fmtx part was wrong when i made the last post
but it didnt help
and by moving the defun part to the top didnt do anything different
still only works when its an xref, doesnt redefine the old block


wrote in message news:5782725@discussion.autodesk.com...
Move the (defun is_xref .. function way up-top, before anything else.. and
this line:
(if (is_xref fmtx)
has variable fmtx .. which I don't see defined.
Change it to:
(if (is_xref blockname)

Bob
Message 13 of 16
Anonymous
in reply to: Anonymous

whats weird is it says its changed but when i list the block it still
displays as the old block
here is what it says

Command: (load "update")
-insert Enter block name or [?] : FMTA1R14=FMTA12K6 Duplicate
Block "FMTA1R14" redefined
Units: Unitless Conversion: 1.00000
Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]:
Command: 110

Command: LIST
Select objects: 1 found

Select objects:
BLOCK REFERENCE Layer: "3"
Space: Model space
Handle = f176
Block Name: "fmta1r14"
at point, X= 0'-0" Y= 0'-0" Z= 0'-0"
X scale factor: 6.00000
Y scale factor: 6.00000
rotation angle: 0d0'0.00"
Z scale factor: 6.00000
Scale uniformly: No
Allow exploding: Yes


wrote in message news:5783195@discussion.autodesk.com...
i realized the fmtx part was wrong when i made the last post
but it didnt help
and by moving the defun part to the top didnt do anything different
still only works when its an xref, doesnt redefine the old block


wrote in message news:5782725@discussion.autodesk.com...
Move the (defun is_xref .. function way up-top, before anything else.. and
this line:
(if (is_xref fmtx)
has variable fmtx .. which I don't see defined.
Change it to:
(if (is_xref blockname)

Bob
Message 14 of 16
Anonymous
in reply to: Anonymous

Does it LOOK the old way? Does REGEN or REGENALL fix that, perhaps?

Or do you mean the Block Name is still listed as the old one? That won't be "fixed" by redefining
the block. You would need to RENAME it, too.

--
Kent Cooper


wrote...
whats weird is it says its changed but when i list the block it still
displays as the old block
here is what it says

Command: (load "update")
-insert Enter block name or [?] : FMTA1R14=FMTA12K6 Duplicate
Block "FMTA1R14" redefined
Units: Unitless Conversion: 1.00000
Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]:
Command: 110

Command: LIST
Select objects: 1 found

Select objects:
BLOCK REFERENCE Layer: "3"
Space: Model space
Handle = f176
Block Name: "fmta1r14"
at point, X= 0'-0" Y= 0'-0" Z= 0'-0"
X scale factor: 6.00000
Y scale factor: 6.00000
rotation angle: 0d0'0.00"
Z scale factor: 6.00000
Scale uniformly: No
Allow exploding: Yes


wrote in message news:5783195@discussion.autodesk.com...
i realized the fmtx part was wrong when i made the last post
but it didnt help
and by moving the defun part to the top didnt do anything different
still only works when its an xref, doesnt redefine the old block


wrote in message news:5782725@discussion.autodesk.com...
Move the (defun is_xref .. function way up-top, before anything else.. and
this line:
(if (is_xref fmtx)
has variable fmtx .. which I don't see defined.
Change it to:
(if (is_xref blockname)

Bob
Message 15 of 16
Anonymous
in reply to: Anonymous

umm... $hit...

i thought it was supposed to change the block name as well as the
information in the block?

ok call me stupid

Bob I appreciate your help & I appolgize for wasting your time its been
working since your 3rd reply.

Kent thanks for smacking me in the head. I have understood it in a wrong way
for a while.



"Kent Cooper" wrote in message
news:5783231@discussion.autodesk.com...
Does it LOOK the old way? Does REGEN or REGENALL fix that, perhaps?

Or do you mean the Block Name is still listed as the old one? That won't be
"fixed" by redefining
the block. You would need to RENAME it, too.

--
Kent Cooper


wrote...
whats weird is it says its changed but when i list the block it still
displays as the old block
here is what it says

Command: (load "update")
-insert Enter block name or [?] : FMTA1R14=FMTA12K6 Duplicate
Block "FMTA1R14" redefined
Units: Unitless Conversion: 1.00000
Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]:
Command: 110

Command: LIST
Select objects: 1 found

Select objects:
BLOCK REFERENCE Layer: "3"
Space: Model space
Handle = f176
Block Name: "fmta1r14"
at point, X= 0'-0" Y= 0'-0" Z= 0'-0"
X scale factor: 6.00000
Y scale factor: 6.00000
rotation angle: 0d0'0.00"
Z scale factor: 6.00000
Scale uniformly: No
Allow exploding: Yes


wrote in message news:5783195@discussion.autodesk.com...
i realized the fmtx part was wrong when i made the last post
but it didnt help
and by moving the defun part to the top didnt do anything different
still only works when its an xref, doesnt redefine the old block


wrote in message news:5782725@discussion.autodesk.com...
Move the (defun is_xref .. function way up-top, before anything else.. and
this line:
(if (is_xref fmtx)
has variable fmtx .. which I don't see defined.
Change it to:
(if (is_xref blockname)

Bob
Message 16 of 16
Anonymous
in reply to: Anonymous

I prefer to think of it as just giving you a little nudge....wouldn't want to hurt anybody....
--
Kent Cooper


wrote...
umm... $hit...
....
Kent thanks for smacking me in the head. I have understood it in a wrong way
for a while.
....

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost