.NET
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Getattribu te problem
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
639 Views, 6 Replies
05-28-2009 08:03 AM
Hi,
I have a big problem to obtain the attribute linked to a block reference:
//CODE
AcadDocuments objAcadDocs = objAcadApp.Documents;
AcadDocument objAcadDoc = objAcadDocs.Open(filePath, true, "");
AcadBlocks objAcadBlks = objAcadDoc.Blocks;
foreach (AcadEntity objAcadEnty in objAcadDoc.ModelSpace)
{
if (objAcadEnty is AcadBlockReference)
{
AcadBlockReference objAcadBlkRef = (AcadBlockReference)objAcadEnty;
if (objAcadBlkRef.HasAttributes == true)
{
AcadAttributeReference objAcadAttRef = (AcadAttributeReferenceClass)objAcadBlkRef.GetAttr ibutes();
}
}
}
I'm using VS2005 with Autocad2004 (ActiveX API).
Thank for help
/Stefano
I have a big problem to obtain the attribute linked to a block reference:
//CODE
AcadDocuments objAcadDocs = objAcadApp.Documents;
AcadDocument objAcadDoc = objAcadDocs.Open(filePath, true, "");
AcadBlocks objAcadBlks = objAcadDoc.Blocks;
foreach (AcadEntity objAcadEnty in objAcadDoc.ModelSpace)
{
if (objAcadEnty is AcadBlockReference)
{
AcadBlockReference objAcadBlkRef = (AcadBlockReference)objAcadEnty;
if (objAcadBlkRef.HasAttributes == true)
{
AcadAttributeReference objAcadAttRef = (AcadAttributeReferenceClass)objAcadBlkRef.GetAttr
}
}
}
I'm using VS2005 with Autocad2004 (ActiveX API).
Thank for help
/Stefano
Re: Getattribu te problem
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-28-2009 10:44 AM in reply to:
zitsmi
COM method AcadBlockReference.GetAttributes() returns an array of AcadAttributeReference, not a single AcadAttributeReference. This is why your doe is not working: you are trying to cast an array of AcadAttributeReference to a single AcadAttributeReference
Re: Getattribu te problem
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-28-2009 11:46 PM in reply to:
zitsmi
norman.yuan,
how can I cast the array from AcadBlockReference.GetAttributes() to an array of AcadAttributeReference?
I've tried a lot but without success: can you provide me the code?
Thank you for your help, I'm desperate!
/Stefano
how can I cast the array from AcadBlockReference.GetAttributes() to an array of AcadAttributeReference?
I've tried a lot but without success: can you provide me the code?
Thank you for your help, I'm desperate!
/Stefano
*Norman Yuan
Re: Getattribu te problem
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-29-2009 05:23 AM in reply to:
zitsmi
It could be like this:
...
if
(objAcadBlkRef.HasAttributes)
(objAcadBlkRef.HasAttributes)
{
//Loop
through the attributs
through the attributs
foreach
(AcadAttributeReference att as AcadAttributeReference in
objAcadBlkRef.GetAttributs())
(AcadAttributeReference att as AcadAttributeReference in
objAcadBlkRef.GetAttributs())
(
switch (att.TagString.ToUpper())
{
case "TAG1":
...
break;
case "TAG2"
...
break;
...
}
}
}
Or
...
if
(objAcadBlkRef.HasAttributes)
(
AcadAttributeReference att=(AcadAttributeReference) obj;
switch (att.TagString.ToUpper())
{
case "TAG1":
...
break;
case "TAG2"
...
break;
...
}
}
(objAcadBlkRef.HasAttributes)
{
//Loop
through the attributs
through the attributs
foreach
(object obj in objAcadBlkRef.GetAttributs())
(object obj in objAcadBlkRef.GetAttributs())
(
AcadAttributeReference att=(AcadAttributeReference) obj;
switch (att.TagString.ToUpper())
{
case "TAG1":
...
break;
case "TAG2"
...
break;
...
}
}
}
Or
...
if
(objAcadBlkRef.HasAttributes)
AcadAttributeReference att=(AcadAttributeReference)obj;
(objAcadBlkRef.HasAttributes)
{
object[]
objs=objAcadBlkRef.GetAttributes();
objs=objAcadBlkRef.GetAttributes();
foreach (object obj in objs)
{
AcadAttributeReference att=(AcadAttributeReference)obj;
...
}
}
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<zitsmi> wrote in messagenorman.yuan,
href="news:6191669@discussion.autodesk.com">news:6191669@discussion.autodesk.com...
how can I cast the array from AcadBlockReference.GetAttributes() to an array
of AcadAttributeReference? I've tried a lot but without success: can you
provide me the code? Thank you for your help, I'm desperate!
/Stefano
Re: Getattribu te problem
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-29-2009 06:32 AM in reply to:
zitsmi
Sorry Norman Yuan,
it still doesn't work.
Example n°1:
Syntax error
Example n°2:
I receive error --> foreach statement cannot operate on variables of type 'object' because 'object' does not contain a public definition for 'GetEnumerator'
Example n°3 :
I receive error --> Cannot implicitly convert type 'object' to 'object[]'. An explicit conversion exists (are you missing a cast?)
It's like method GetAttributes return a single object, not an Array
Probably I'm confused about Autocad 2004 Object Model...
Thank you again!!
it still doesn't work.
Example n°1:
Syntax error
Example n°2:
I receive error --> foreach statement cannot operate on variables of type 'object' because 'object' does not contain a public definition for 'GetEnumerator'
Example n°3 :
I receive error --> Cannot implicitly convert type 'object' to 'object[]'. An explicit conversion exists (are you missing a cast?)
It's like method GetAttributes return a single object, not an Array
Probably I'm confused about Autocad 2004 Object Model...
Thank you again!!
*Tony Tanzillo
Re: Getattribu te problem
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-29-2009 06:43 AM in reply to:
zitsmi
Try:
{code}
object[] attributes = (object[]) blockrefObj.GetAttributes()
foreach( AcadAttributeReference att in attributes )
{
// ...
}
{code}
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009
http://www.acadxtabs.com
Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.ht m
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");
wrote in message news:6191850@discussion.autodesk.com...
Sorry Norman Yuan, it still doesn't work. Example n°1: Syntax error Example
n°2: I receive error --> foreach statement cannot operate on variables of
type 'object' because 'object' does not contain a public definition for
'GetEnumerator' Example n°3 : I receive error --> Cannot implicitly convert
type 'object' to 'object[]'. An explicit conversion exists (are you missing
a cast?) It's like method GetAttributes return a single object, not an Array
Probably I'm confused about Autocad 2004 Object Model... Thank you again!!
{code}
object[] attributes = (object[]) blockrefObj.GetAttributes()
foreach( AcadAttributeReference att in attributes )
{
// ...
}
{code}
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009
http://www.acadxtabs.com
Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.ht
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");
Sorry Norman Yuan, it still doesn't work. Example n°1: Syntax error Example
n°2: I receive error --> foreach statement cannot operate on variables of
type 'object' because 'object' does not contain a public definition for
'GetEnumerator' Example n°3 : I receive error --> Cannot implicitly convert
type 'object' to 'object[]'. An explicit conversion exists (are you missing
a cast?) It's like method GetAttributes return a single object, not an Array
Probably I'm confused about Autocad 2004 Object Model... Thank you again!!
Re: Getattribu te problem
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-29-2009 07:05 AM in reply to:
zitsmi
IT WORKS!!!
Thank you Tony, thank you Norman Yuan!!
Thank you Tony, thank you Norman Yuan!!

