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

Block or Xref object?

10 REPLIES 10
Reply
Message 1 of 11
Anonymous
867 Views, 10 Replies

Block or Xref object?

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
10 REPLIES 10
Message 2 of 11
H.vanZeeland
in reply to: Anonymous

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
Message 3 of 11
Anonymous
in reply to: Anonymous

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
Message 4 of 11
H.vanZeeland
in reply to: Anonymous

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
Message 5 of 11
Anonymous
in reply to: Anonymous

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
Message 6 of 11
Kent1Cooper
in reply to: Anonymous

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, AIA
Message 7 of 11
Anonymous
in reply to: Anonymous

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
Message 8 of 11
Anonymous
in reply to: Anonymous

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
Message 9 of 11
Anonymous
in reply to: Anonymous

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
Message 10 of 11
H.vanZeeland
in reply to: Anonymous

Hi Russ,



I putted together.

See attached file.





Hope this helps.



Cheers



Harrie
Message 11 of 11
Anonymous
in reply to: Anonymous

wow! many thanks Harrie that's great! I reckon it would take me about 100
years to get to your level of coding.
....and thanks to Gile and everyone else - beers all round today from me!
Russ


wrote in message news:6152430@discussion.autodesk.com...
Hi Russ,



I putted together.

See attached file.





Hope this helps.



Cheers



Harrie

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

Post to forums  

Autodesk Design & Make Report

”Boost