Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
*Kiwi Russ
Message 1 of 11 (243 Views)

Block or Xref object?

243 Views, 10 Replies
03-28-2009 02:24 PM
I would like to differentiate between blocks and xrefs when
'vla-get-ObjectName' is used
- It returns the name 'acdbBlock' regardless of whether it is a block or an
xref.
The below code (thanks to Gile) returns a dotted pair list .
I want to modify it so that it can return the name block or xref when
appropiate.

(setq ent (nentsel"\nSelect object: "))
(setq lst
(mapcar '(lambda (x)
(setq x (vlax-ename->vla-object x))
(cons
(vla-get-ObjectName x))
(vla-get-Layer x) ))
(if (caddr ent) (cons (car ent) (last ent)) ; nested
(list (car ent)) ; not nested
) ) )

This is my attempt which does not work!


(setq ent (nentsel"\nSelect object: "))
(setq lst
(mapcar '(lambda (x)
(setq x (vlax-ename->vla-object x))
(cons
(vla-get-ObjectName (CheckBlkXref x)); I have added in function here
(vla-get-Layer x) ))
(if (caddr ent) (cons (car ent) (last ent)) ; nested
(list (car ent)) ; not nested
) ) )

my function

(defun CheckBlkXref ( ent / blocks xref xrefname xrefdef)
(setq blocks
(vla-get-blocks
(vla-get-activedocument
(vlax-get-acad-object))))
(setq xref (last (last ent)))
(setq xref (vlax-ename->vla-object xref))
;; Name of the xref/block
(setq xrefname (vlax-get xref 'Name))
;; Xref /block definition
(setq xrefdef (vla-item blocks xrefname))
;; Test the block is an xref
(if (= -1 (vlax-get xrefdef 'IsXref))
(setq x "xref")
);if
);defun

thanks Russ
Distinguished Contributor
H.vanZeeland
Posts: 664
Registered: ‎12-11-2003
Message 2 of 11 (243 Views)

Re: Block or Xref object?

03-29-2009 02:27 AM in reply to: *Kiwi Russ
Hi,





(setq ent (nentsel"\nSelect object: "))

(setq blocks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))

(setq lst

(vl-remove nil (mapcar (function (lambda (x)

(setq x (vlax-ename->vla-object x))

(if (not (and (= (vla-get-ObjectName x) "AcDbBlockReference")

(= (vla-get-IsXRef (vla-item blocks (vla-get-name x))) :vlax-false)))

(cons

(vla-get-ObjectName x)

(vla-get-Layer x)))))

(if (caddr ent) (cons (car ent) (last ent)) ; nested

(list (car ent)) ; not nested

) )))



Cheers

Harrie
*Kiwi Russ
Message 3 of 11 (243 Views)

Re: Block or Xref object?

03-29-2009 08:36 PM in reply to: *Kiwi Russ
Thanks Harrie
I might be not that clear in what I am trying to achieve. (unless I
misunderstand your code)
Rather than delete the dotted pair when a Xref object appears I want to
include it in the dotted pair list.
If I have a for example, an xref on the first level, then a block on the
second level, and a pline on the
third level then I would get a list similar to :

Lst = ( (AcDbBlockReference . mylayer2) (AcDbBlockReference . mylayer5)
(AcDbPolyline . mylayer6) )
As you can see there is no differentiation between block and xref

The xref and block are know by the same name- ie 'AcDbBlockReference'

I want something like:

Lst = ( (xref . mylayer2) (AcDbBlockReference . mylayer5) (AcDbPolyline .
mylayer6) )

Or maybe

Lst = ( (xref . mylayer2) (block . mylayer5) (AcDbPolyline .
mylayer6) )

Russ




wrote in message news:6151315@discussion.autodesk.com...

<(setq ent (nentsel"\nSelect object: "))

(setq blocks (vla-get-blocks (vla-get-activedocument
(vlax-get-acad-object))))

(setq lst

(vl-remove nil (mapcar (function (lambda (x)

(setq x (vlax-ename->vla-object x))

(if (not (and (= (vla-get-ObjectName x) "AcDbBlockReference")

(= (vla-get-IsXRef (vla-item blocks (vla-get-name x))) :vlax-false)))

(cons

(vla-get-ObjectName x)

(vla-get-Layer x)))))

(if (caddr ent) (cons (car ent) (last ent)) ; nested

(list (car ent)) ; not nested

) )))



Cheers

Harrie
Distinguished Contributor
H.vanZeeland
Posts: 664
Registered: ‎12-11-2003
Message 4 of 11 (243 Views)

Re: Block or Xref object?

03-30-2009 12:40 AM in reply to: *Kiwi Russ
Hi,





(setq ent (nentsel"\nSelect object: "))

(setq blocks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))

(setq lst

(mapcar (function (lambda (x)

(setq x (vlax-ename->vla-object x))

(cons

(if (and (= (vla-get-ObjectName x) "AcDbBlockReference")

(= (vla-get-IsXRef (vla-item blocks (vla-get-name x))) :vlax-false))

"Xref"

(vla-get-ObjectName x)

);end if

(vla-get-Layer x))))

(if (caddr ent) (cons (car ent) (last ent)) ; nested

(list (car ent)) ; not nested

) ))





Cheers

Harrie
*Joe Burke
Message 5 of 11 (243 Views)

Re: Block or Xref object?

03-30-2009 05:42 AM in reply to: *Kiwi Russ
Hi Russ,

Maybe something like this. Test for the Path property.

(setq ent (nentsel "\nSelect nested object: "))
(if (vlax-property-available-p
(vlax-ename->vla-object (last (last ent))) 'Path)
(princ "\nObject is nested in an xref. ")
(princ "\nObject is nested in an block. ")
)

Joe Burke


"Kiwi Russ" wrote in message news:6151266@discussion.autodesk.com...
I would like to differentiate between blocks and xrefs when
'vla-get-ObjectName' is used
- It returns the name 'acdbBlock' regardless of whether it is a block or an
xref.
The below code (thanks to Gile) returns a dotted pair list .
I want to modify it so that it can return the name block or xref when
appropiate.

(setq ent (nentsel"\nSelect object: "))
(setq lst
(mapcar '(lambda (x)
(setq x (vlax-ename->vla-object x))
(cons
(vla-get-ObjectName x))
(vla-get-Layer x) ))
(if (caddr ent) (cons (car ent) (last ent)) ; nested
(list (car ent)) ; not nested
) ) )

This is my attempt which does not work!


(setq ent (nentsel"\nSelect object: "))
(setq lst
(mapcar '(lambda (x)
(setq x (vlax-ename->vla-object x))
(cons
(vla-get-ObjectName (CheckBlkXref x)); I have added in function here
(vla-get-Layer x) ))
(if (caddr ent) (cons (car ent) (last ent)) ; nested
(list (car ent)) ; not nested
) ) )

my function

(defun CheckBlkXref ( ent / blocks xref xrefname xrefdef)
(setq blocks
(vla-get-blocks
(vla-get-activedocument
(vlax-get-acad-object))))
(setq xref (last (last ent)))
(setq xref (vlax-ename->vla-object xref))
;; Name of the xref/block
(setq xrefname (vlax-get xref 'Name))
;; Xref /block definition
(setq xrefdef (vla-item blocks xrefname))
;; Test the block is an xref
(if (= -1 (vlax-get xrefdef 'IsXref))
(setq x "xref")
);if
);defun

thanks Russ
*Expert Elite*
Kent1Cooper
Posts: 5,411
Registered: ‎09-13-2004
Message 6 of 11 (243 Views)

Re: Block or Xref object?

03-30-2009 06:50 AM in reply to: *Kiwi Russ
Here's a way to distinguish Blocks from Xref's, with 'objdata' being the object's entity-data list such as you would get from (entget):

(= (logand 4 (cdr (assoc 70 (tblsearch "block" (cdr (assoc 2 objdata)))))) 4)

If that returns T, it's an Xref; otherwise, it's a Block insertion. You would need to force-substitute the 'xref' part into your dotted pair in the result you're looking for.

--
Kent Cooper


Kiwi Russ wrote:

I would like to differentiate between blocks and xrefs when 'vla-get-ObjectName' is used - It returns the name 'acdbBlock' regardless of whether it is a block or an xref.
....
Kent Cooper
*Some Buddy
Message 7 of 11 (243 Views)

Re: Block or Xref object?

03-30-2009 07:14 AM in reply to: *Kiwi Russ
Hi Kiwi,

Try the following function. Use it like:

(setq lst (myfunc))

;;;================================
(defun myfunc ( / blocks ent)
(vl-load-com)
(setq blocks
(vla-get-blocks
(vla-get-activedocument
(vlax-get-acad-object)
)
)
)
(setq ent (nentsel"\nSelect object: "))
(mapcar
'(lambda (x / y)
(setq y (vlax-ename->vla-object x))
(if
(and
(=
(vla-get-objectname y)
"AcDbBlockReference"
)
(=
(vla-get-isxref
(vla-item
(vla-get-blocks
(vla-get-activedocument
(vlax-get-acad-object)
)
)
(vla-get-name y)
)
)
:vlax-true
)
)
(cons 'xref (vla-get-layer y))
(cons (vla-get-objectname y)(vla-get-layer y))
)
)
(if (caddr ent)
(cons (car ent)(last ent))
(list (car ent))
)
)
)
;;;================================

HTH

--
Humans are born with a wide horizon.
As time goes by, the horizon narrows and
narrows, until it becomes a point of view.


"Kiwi Russ" a écrit dans le message de news:
6151475@discussion.autodesk.com...
Thanks Harrie
I might be not that clear in what I am trying to achieve. (unless I
misunderstand your code)
Rather than delete the dotted pair when a Xref object appears I want to
include it in the dotted pair list.
If I have a for example, an xref on the first level, then a block on the
second level, and a pline on the
third level then I would get a list similar to :

Lst = ( (AcDbBlockReference . mylayer2) (AcDbBlockReference . mylayer5)
(AcDbPolyline . mylayer6) )
As you can see there is no differentiation between block and xref

The xref and block are know by the same name- ie 'AcDbBlockReference'

I want something like:

Lst = ( (xref . mylayer2) (AcDbBlockReference . mylayer5) (AcDbPolyline .
mylayer6) )

Or maybe

Lst = ( (xref . mylayer2) (block . mylayer5) (AcDbPolyline .
mylayer6) )

Russ




wrote in message news:6151315@discussion.autodesk.com...

<(setq ent (nentsel"\nSelect object: "))

(setq blocks (vla-get-blocks (vla-get-activedocument
(vlax-get-acad-object))))

(setq lst

(vl-remove nil (mapcar (function (lambda (x)

(setq x (vlax-ename->vla-object x))

(if (not (and (= (vla-get-ObjectName x) "AcDbBlockReference")

(= (vla-get-IsXRef (vla-item blocks (vla-get-name x))) :vlax-false)))

(cons

(vla-get-ObjectName x)

(vla-get-Layer x)))))

(if (caddr ent) (cons (car ent) (last ent)) ; nested

(list (car ent)) ; not nested

) )))



Cheers

Harrie
*Some Buddy
Message 8 of 11 (243 Views)

Re: Block or Xref object?

03-30-2009 07:27 AM in reply to: *Kiwi Russ
After reading the answers to your other post "Lists from dotted pairs" I
think that it would be better for you if you replace the line:

(cons 'xref (vla-get-layer y))

which is what you've asked, with

(cons "Xref" (vla-get-layer y))

which will be very helpful when you will want to concatenate it.

HTH



--
Humans are born with a wide horizon.
As time goes by, the horizon narrows and
narrows, until it becomes a point of view.

"Kiwi Russ" a écrit dans le message de news:
6151475@discussion.autodesk.com...
Thanks Harrie
I might be not that clear in what I am trying to achieve. (unless I
misunderstand your code)
Rather than delete the dotted pair when a Xref object appears I want to
include it in the dotted pair list.
If I have a for example, an xref on the first level, then a block on the
second level, and a pline on the
third level then I would get a list similar to :

Lst = ( (AcDbBlockReference . mylayer2) (AcDbBlockReference . mylayer5)
(AcDbPolyline . mylayer6) )
As you can see there is no differentiation between block and xref

The xref and block are know by the same name- ie 'AcDbBlockReference'

I want something like:

Lst = ( (xref . mylayer2) (AcDbBlockReference . mylayer5) (AcDbPolyline .
mylayer6) )

Or maybe

Lst = ( (xref . mylayer2) (block . mylayer5) (AcDbPolyline .
mylayer6) )

Russ




wrote in message news:6151315@discussion.autodesk.com...

<(setq ent (nentsel"\nSelect object: "))

(setq blocks (vla-get-blocks (vla-get-activedocument
(vlax-get-acad-object))))

(setq lst

(vl-remove nil (mapcar (function (lambda (x)

(setq x (vlax-ename->vla-object x))

(if (not (and (= (vla-get-ObjectName x) "AcDbBlockReference")

(= (vla-get-IsXRef (vla-item blocks (vla-get-name x))) :vlax-false)))

(cons

(vla-get-ObjectName x)

(vla-get-Layer x)))))

(if (caddr ent) (cons (car ent) (last ent)) ; nested

(list (car ent)) ; not nested

) )))



Cheers

Harrie
*Kiwi Russ
Message 9 of 11 (243 Views)

Re: Block or Xref object?

03-30-2009 09:20 PM in reply to: *Kiwi Russ
Thanks everyone for your inputs. The code works well.
Just one little adjustment. I want to add the name of the xref or block to
the final output.
I can find the block/xref name using:

(setq blocks
(vla-get-blocks
(vla-get-activedocument
(vlax-get-acad-object))))
(setq xref (last (last ent)))
(setq xref-block-ename (vlax-ename->vla-object xref))
(setq xref-block-name (vlax-get xref-block-ename 'Name))

but thats the easy bit!

My question is where can I add the above into the code I have so far.
Would I need to make a separate function? and then add it into the final
alert/princ string?
I tried that but it doesn't like it - along every other possibilty.
Maybe Harrie could tell me as he posted the final string (from a previous
post) ie

(strcat "\nLevel " (itoa (setq i (1+ i)))" Object is a <"
(ConvToUserFriendly obj) "> " "on layer" "\"" layer "\"")

My guess is that this above line needs to be adjusted
Thanks
Russ
Distinguished Contributor
H.vanZeeland
Posts: 664
Registered: ‎12-11-2003
Message 10 of 11 (243 Views)

Re: Block or Xref object?

03-31-2009 01:30 AM in reply to: *Kiwi Russ
Hi Russ,



I putted together.

See attached file.





Hope this helps.



Cheers



Harrie
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.