.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

AutoCAD.Net Problem Arraying Dynamic Blocks

6 REPLIES 6
Reply
Message 1 of 7
Anonymous
1401 Views, 6 Replies

AutoCAD.Net Problem Arraying Dynamic Blocks

Hi,

I hope someone can help with this one as i have searched the forums and the Autodesk API documentation and have come up empty.

I has some code in VB.NET using the Autodesk managed API to insert blocks (static and dynamic) from a repository, as it inserts the blocks it sets attributes and dynamic property values. (This part works fine)

The function I am having issues with arrays an already inserted blocks (again static and dynamic, this is working perfectly for the static blocks)
My comments in brackets are describing the issue however in summary when i attempt to create a new blockreference to one of the dynamic blocks and add it to the database it forgets (not the best word i know) that it is a dynamic block and becomes static.

Here is the section of code in question:

Dim currentblocktable As BlockTable = currentTransaction.GetObject(currentDatabase.BlockTableId, OpenMode.ForRead)
Dim currentBlockTableRecord As BlockTableRecord = currentTransaction.GetObject( _
currentblocktable(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
Dim columns As Integer = 1
Dim rows As Integer = 1

While columns < numberOfColumns

(At this point the _blockReference object has been retrieved from its ObjectID which is passed into the arraying function)
Dim newBlockRef As BlockReference = _blockReference.Clone()
(If at this point i retrieve the DynamicBlockTableRecord of the cloned object it returns the correct entry)

Dim newPoint As Point2d = PolarPoints(arrayBasePoint, 0, arrayProperties.HorizontalSpacing * columns + 1)
Dim vec2d As Vector2d = arrayBasePoint.GetVectorTo(newPoint)
Dim vec3d As Vector3d = New Vector3d(vec2d.X, vec2d.Y, 0)
newBlockRef.TransformBy(Matrix3d.Displacement(vec3d))

(If at this point i retrieve the DynamicBlockTableRecord of the cloned object it returns the correct entry)
currentBlockTableRecord.AppendEntity(newBlockRef)
(From this point on the BlockReference which the object newBlockReference refers to is no longer dynamic and if i return the
BlockTableRecord or the DynamicBlockTableRecord for this it refers to a block called *Uxxx where
xxx is a numeric value, I understand that this blockRecord is part of the make up of the Dynamic block but why is it losing the
reference to the correct DynamicBlockTableRecord when it is appended to modelspace?)

currentTransaction.AddNewlyCreatedDBObject(newBlockRef, True)
columns += 1
End While

Finally is there a good place to go for an explanation of what the clone function actually does? As i have googled the life out of it and cant find any explanation of what this function actually does so am calling it blindly and examining the results. Which i dont like doing!


Any Help appreciated thanks. Edited by: PSharpe on Jun 1, 2010 10:03 AM
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: Anonymous

You shouldn't be calling Clone() to do what you need.

You need to call the Database's DeepCloneObjects()
method, if the intention is to "copy" an existing object.

Alternately, you could call the ActiveX Copy() method,
which is basically a wrapper around DeepCloneObjects()
that also takes care of the all the related grunt work.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

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

I hope someone can help with this one as i have searched the forums and the
Autodesk API documentation and have come up empty.

I has some code in VB.NET using the Autodesk managed API to insert blocks
(static and dynamic) from a repository, as it inserts the blocks it sets
attributes and dynamic property values. (This part works fine)

The function I am having issues with arrays an already inserted blocks (again
static and dynamic, this is working perfectly for the static blocks)
My comments in brackets are describing the issue however in summary when i
attempt to create a new blockreference to one of the dynamic blocks and add it
to the database it forgets (not the best word i know) that it is a dynamic block
and becomes static.

Here is the section of code in question:

Dim currentblocktable As BlockTable =
currentTransaction.GetObject(currentDatabase.BlockTableId, OpenMode.ForRead)
Dim currentBlockTableRecord As BlockTableRecord =
currentTransaction.GetObject( _
currentblocktable(BlockTableRecord.ModelSpace),
OpenMode.ForWrite)
Dim columns As Integer = 1
Dim rows As Integer = 1

While columns < numberOfColumns

(At this point the _blockReference object has been retrieved
from its ObjectID which is passed into the arraying function)
Dim newBlockRef As BlockReference = _blockReference.Clone()
(If at this point i retrieve the DynamicBlockTableRecord of the
cloned object it returns the correct entry)

Dim newPoint As Point2d = PolarPoints(arrayBasePoint, 0,
arrayProperties.HorizontalSpacing * columns + 1)
Dim vec2d As Vector2d = arrayBasePoint.GetVectorTo(newPoint)
Dim vec3d As Vector3d = New Vector3d(vec2d.X, vec2d.Y, 0)
newBlockRef.TransformBy(Matrix3d.Displacement(vec3d))

(If at this point i retrieve the DynamicBlockTableRecord of the
cloned object it returns the correct entry)
currentBlockTableRecord.AppendEntity(newBlockRef)
(From this point on the BlockReference which the object
newBlockReference refers to is no longer dynamic and if i return the
BlockTableRecord or the DynamicBlockTableRecord for this it
refers to a block called *Uxxx where
xxx is a numeric value, I understand that this blockRecord is
part of the make up of the Dynamic block but why is it losing the
reference to the correct DynamicBlockTableRecord when it is
appended to modelspace?)

currentTransaction.AddNewlyCreatedDBObject(newBlockRef, True)
columns += 1
End While

Finally is there a good place to go for an explanation of what the clone
function actually does? As i have googled the life out of it and cant find any
explanation of what this function actually does so am calling it blindly and
examining the results. Which i dont like doing!


Any Help appreciated thanks.

Edited by: PSharpe on Jun 1, 2010 10:03 AM
Message 3 of 7
Anonymous
in reply to: Anonymous

Ok thank you for the advice i will try this when i get into the office tomorrow.

Do you know of a good resource for an explanation of what functions like Clone and DeepCloneObjects do?
I have searched through the API documentation online and it doesn't really offer any descriptions of what functions like this do or why you should use one over the other. I would really like to understand why these things need to be done in these specific ways.

Again thanks for the assistance
Message 4 of 7
Anonymous
in reply to: Anonymous

The native ObjectARX documentation is the best source of
information right now, for more detail on individual APIs.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6400772@discussion.autodesk.com...
Ok thank you for the advice i will try this when i get into the office tomorrow.

Do you know of a good resource for an explanation of what functions like Clone
and DeepCloneObjects do?
I have searched through the API documentation online and it doesn't really offer
any descriptions of what functions like this do or why you should use one over
the other. I would really like to understand why these things need to be done in
these specific ways.

Again thanks for the assistance
Message 5 of 7
Anonymous
in reply to: Anonymous

I have resolved this isuue now though not in the way im sure Tony was suggesting.

I did have a look at the DeepClone and DeepCloneObject functions but as they do not return any ObjectID references or any other such indicator as to retrieving the cloned objects for manipulation I have found another way.

An observation - The Clone function as Tony said does appear to ignore the DynamicBlockTableRecord property of a BlockReference object when calling the clone function, though it does appear to deal this the BlockTableRecord as expected.

To achieve what i was after here I had to create a new BlockReference as follows:

newBlockRef = New BlockReference(_blockReference.Position, _blockReference.DynamicBlockTableRecord)

where _blockReference is the original blockReference Object

Then copy the attributes accross from the original

{
For Each objID As ObjectId In _blockReference.AttributeCollection
Dim newAttref As AttributeReference = objID.GetObject(OpenMode.ForWrite).Clone()
newAttref.SetAttributeFromBlock(Matrix3d.Displacement(vec3d))
newBlockRef.AttributeCollection.AppendAttribute(newAttref)
currentTransaction.AddNewlyCreatedDBObject(newAttref, True)
Next
}

and set the DynamicBlockProperties after this.

Im convinced this is not the correct/best way to accomplish what I this functionality though it does work.

If anyone can tell me how i should have done this i would be gratefull Edited by: psharpe on Jun 2, 2010 9:24 AM
Message 6 of 7
Anonymous
in reply to: Anonymous

{quote}

I did have a look at the DeepClone and DeepCloneObject functions but as they do
not return any ObjectID references or any other such indicator as to retrieving
the cloned objects for manipulation I have found another way.

{quote}

No, it doesn't return the objectids of the new copies, it adds them
to the IdMapping that you must pass as an argument, which you
can subsequently use to map each source object to its new copy,
and manipulate all of the copied objects.

Didn't you wonder what the IdMapping argument was, and/or
what it was for?

You create a new IdMapping object, and pass it to DeepCloneObjects,
and after the call returns you can iterate through the mapping using
foreach( IdPair pair in myIdMapping ), and each IdPair whose IsPrimary
property is set to true, holds the Id of an original/source object in the
Key property, and the Id of the copy of that source object in the Value
property.

If not sure, ask and we'll help you. Also search the newsgroups
(although you may not be able to do that any longer in a few days)
on the name of the method, for more help.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6401194@discussion.autodesk.com...
I have resolved this isuue now though not in the way im sure Tony was
suggesting.

I did have a look at the DeepClone and DeepCloneObject functions but as they do
not return any ObjectID references or any other such indicator as to retrieving
the cloned objects for manipulation I have found another way.

An observation - The Clone function as Tony said does appear to ignore the
DynamicBlockTableRecord property of a BlockReference object when calling the
clone function, though it does appear to deal this the BlockTableRecord as
expected.

To achieve what i was after here I had to create a new BlockReference as
follows:

newBlockRef = New BlockReference(_blockReference.Position,
_blockReference.DynamicBlockTableRecord)

where _blockReference is the original blockReference Object

Then copy the attributes accross from the original

{
For Each objID As ObjectId In _blockReference.AttributeCollection
Dim newAttref As AttributeReference =
objID.GetObject(OpenMode.ForWrite).Clone()
newAttref.SetAttributeFromBlock(Matrix3d.Displacement(vec3d))
newBlockRef.AttributeCollection.AppendAttribute(newAttref)
currentTransaction.AddNewlyCreatedDBObject(newAttref, True)
Next
}

and set the DynamicBlockProperties after this.

Im convinced this is not the correct/best way to accomplish what I this
functionality though it does work.

If anyone can tell me how i should have done this i would be gratefull

Edited by: psharpe on Jun 2, 2010 9:24 AM
Message 7 of 7
Anonymous
in reply to: Anonymous

"Tony Tanzillo" wrote in message
news:6401546@discussion.autodesk.com...
{quote}
snip

Also search the newsgroups
(although you may not be able to do that any longer in a few days)
on the name of the method, for more help.

curious if there will be other servers carrying this ng or is it gone for
good?
I know the ms groups that are disappearing will still exist in the nntp
ether at sites like eternal-september
don't know enough about nntp to know if that will be possible with adesk
groups?
are you resigned to using the web forums? or is there an alternate nntp
world I dont' know about to continue this heirarchy despite adesks'
misguided decision to follow ms in every user unfriendly "improvement"?
mark

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost