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

Setting Properties of Dynamic Blocks not as expected

2 REPLIES 2
Reply
Message 1 of 3
marco
356 Views, 2 Replies

Setting Properties of Dynamic Blocks not as expected

I wrote some code to insert a dynamic block including some specified DynamicBlockReferenceProperties.
On screen all goes well: The Dynamic block appears with the specified properties set.
But when I want to change one of the properties it appears the block has the standard properties instead of the ones that I set and appear on the screen.
When I change the visibility for example the block appears to stay the same, but when I copy the block the new instance has the changed properties...
What am I missing?

This is the code I'm using. I also attached a screenshot where you can see the 'fixed' visibility of the block and the real visibility shown by the jig.

Marco

{code}
Imports adskR = Autodesk.AutoCAD.Runtime
Imports adskAS = Autodesk.AutoCAD.ApplicationServices
Imports adskEI = Autodesk.AutoCAD.EditorInput
Imports adskDS = Autodesk.AutoCAD.DatabaseServices
Imports adskG = Autodesk.AutoCAD.Geometry
Imports adskW = Autodesk.AutoCAD.Windows

Public Sub CreateElement(ByVal BlockName As String, ByVal VisCode As String, _
ByVal Length As Double, ByVal insPnt As adskG.Point3d, ByVal angle As Double)
'Get the editor
Dim ed As adskEI.Editor = adskAS.Application.DocumentManager.MdiActiveDocument.Editor
'Open the database
Dim dwg As adskDS.Database = ed.Document.Database
'Start a transaction
Dim trans As adskDS.Transaction = dwg.TransactionManager.StartTransaction
Try
'Read the BlockTableRecord from the current BlockTable
Dim ID As adskDS.ObjectId = CType(trans.GetObject(dwg.BlockTableId, adskDS.OpenMode.ForRead, False), adskDS.BlockTable).Item(BlockName)
'Get the blockDefinition
Dim BlockDef As adskDS.BlockTableRecord = CType(dwg.TransactionManager.GetObject(ID, adskDS.OpenMode.ForRead, False), adskDS.BlockTableRecord)
'The block definition exits and a reference can be made.
Dim blockRef As adskDS.BlockReference = New adskDS.BlockReference(insPnt, BlockDef.ObjectId)
blockRef.Rotation = angle
'If the block is a dynamic one change some of it's dynamic properties
If blockRef.IsDynamicBlock Then
For Each DynProp As adskDS.DynamicBlockReferenceProperty In blockRef.DynamicBlockReferencePropertyCollection
'Look only for the changeable ones
If Not DynProp.ReadOnly Then
Select Case UCase(DynProp.PropertyName)
Case "VISIBILITY"
DynProp.Value = VisCode
Case "LENGTE"
DynProp.Value = Length
End Select
End If
Next
End If
'Open the current space for write
Dim curSpace As adskDS.BlockTableRecord = trans.GetObject(dwg.CurrentSpaceId, adskDS.OpenMode.ForWrite)
'Append the block reference to it
curSpace.AppendEntity(blockRef)
trans.AddNewlyCreatedDBObject(blockRef, True)

'Commit the transaction
trans.Commit()
Catch ex As Exception
'A problem occured
ed.WriteMessage("a problem occured because " + ex.Message)
Finally
'Whatever happens, dispose the transaction
trans.Dispose()
End Try
End Sub
{code} Edited by: marco@safe on Nov 12, 2009 4:16 PM
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: marco

I think you need to append the block first, before changing those
properties.

Changing those properties involves creating a new anonymous block to
represent the insertion's graphics, which can't be done if the block is not
in the database.

--
http://www.caddzone.com

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

http://www.acadxtabs.com

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

wrote in message news:6287805@discussion.autodesk.com...
I wrote some code to insert a dynamic block including some specified
DynamicBlockReferenceProperties.
On screen all goes well: The Dynamic block appears with the specified
properties set.
But when I want to change one of the properties it appears the block has the
standard properties instead of the ones that I set and appear on the screen.
When I change the visibility for example the block appears to stay the same,
but when I copy the block the new instance has the changed properties...
What am I missing?

This is the code I'm using. I also attached a screenshot where you can see
the 'fixed' visibility of the block and the real visibility shown by the
jig.

Marco

{code}
Imports adskR = Autodesk.AutoCAD.Runtime
Imports adskAS = Autodesk.AutoCAD.ApplicationServices
Imports adskEI = Autodesk.AutoCAD.EditorInput
Imports adskDS = Autodesk.AutoCAD.DatabaseServices
Imports adskG = Autodesk.AutoCAD.Geometry
Imports adskW = Autodesk.AutoCAD.Windows

Public Sub CreateElement(ByVal BlockName As String, ByVal VisCode As String,
_
ByVal Length As Double, ByVal insPnt As
adskG.Point3d, ByVal angle As Double)
'Get the editor
Dim ed As adskEI.Editor =
adskAS.Application.DocumentManager.MdiActiveDocument.Editor
'Open the database
Dim dwg As adskDS.Database = ed.Document.Database
'Start a transaction
Dim trans As adskDS.Transaction =
dwg.TransactionManager.StartTransaction
Try
'Read the BlockTableRecord from the current BlockTable
Dim ID As adskDS.ObjectId =
CType(trans.GetObject(dwg.BlockTableId, adskDS.OpenMode.ForRead, False),
adskDS.BlockTable).Item(BlockName)
'Get the blockDefinition
Dim BlockDef As adskDS.BlockTableRecord =
CType(dwg.TransactionManager.GetObject(ID, adskDS.OpenMode.ForRead, False),
adskDS.BlockTableRecord)
'The block definition exits and a reference can be made.
Dim blockRef As adskDS.BlockReference = New
adskDS.BlockReference(insPnt, BlockDef.ObjectId)
blockRef.Rotation = angle
'If the block is a dynamic one change some of it's dynamic
properties
If blockRef.IsDynamicBlock Then
For Each DynProp As adskDS.DynamicBlockReferenceProperty In
blockRef.DynamicBlockReferencePropertyCollection
'Look only for the changeable ones
If Not DynProp.ReadOnly Then
Select Case UCase(DynProp.PropertyName)
Case "VISIBILITY"
DynProp.Value = VisCode
Case "LENGTE"
DynProp.Value = Length
End Select
End If
Next
End If
'Open the current space for write
Dim curSpace As adskDS.BlockTableRecord =
trans.GetObject(dwg.CurrentSpaceId, adskDS.OpenMode.ForWrite)
'Append the block reference to it
curSpace.AppendEntity(blockRef)
trans.AddNewlyCreatedDBObject(blockRef, True)

'Commit the transaction
trans.Commit()
Catch ex As Exception
'A problem occured
ed.WriteMessage("a problem occured because " + ex.Message)
Finally
'Whatever happens, dispose the transaction
trans.Dispose()
End Try
End Sub
{code}

Edited by: marco@safe on Nov 12, 2009 4:16 PM
Message 3 of 3
marco
in reply to: marco

Thank you Tony. That did the trick. Simple but logical.

Marco

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