.NET

Reply
Mentor
SRSDS
Posts: 247
Registered: ‎04-15-2011
Message 1 of 9 (413 Views)

Modify Dynamic Block Properties before Jig

413 Views, 8 Replies
06-03-2013 04:26 PM

Hi, 

 

Is there a way to modify the properties of a dynamic block after the insert and before a jig?

 

I've tried a quite a few things but here is some code as a starting point. The blocks are affected by the change but not in a good way. The blocks have several parametric constraints. I wonder if this is part of the problem.

 

    <CommandMethod("TestEntityJigger7")> _
    Public Shared Sub TestEntityJigger7_Method()
        Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
        Dim db As Database = HostApplicationServices.WorkingDatabase
        Dim pr As PromptResult = ed.GetString(vbLf & "Block name:")
        If pr.Status = PromptStatus.OK Then
            Using tr As Transaction = db.TransactionManager.StartTransaction()
                Dim bt As BlockTable = TryCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
                Dim btr As BlockTableRecord = TryCast(tr.GetObject(bt(pr.StringResult), OpenMode.ForRead), BlockTableRecord)
                If btr IsNot Nothing Then
                    Dim br As New BlockReference(New Point3d(0, 0, 0), btr.ObjectId)
                    Dim pc As DynamicBlockReferencePropertyCollection = br.DynamicBlockReferencePropertyCollection
                    For i = 0 To pc.Count - 1
                        Dim prop As DynamicBlockReferenceProperty = pc(i)
                        If prop.PropertyName = "A" Then prop.Value = 1000.0#
                        If prop.PropertyName = "B" Then prop.Value = 2000.0#
                    Next
                    pc.Dispose()
                    If BlockMovingRotating.Jig(br) Then
                        Dim modelspace As BlockTableRecord = TryCast(tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)
                        modelspace.AppendEntity(br)
                        tr.AddNewlyCreatedDBObject(br, True)
                        tr.Commit()
                    Else
                        tr.Abort()
                    End If
                End If
            End Using
        End If
    End Sub

 

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 9 (381 Views)

Re: Modify Dynamic Block Properties before Jig

06-05-2013 01:23 AM in reply to: SRSDS
Firstly, please remove the lines:
Else
tr.Abort()
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 9 (375 Views)

Re: Modify Dynamic Block Properties before Jig

06-05-2013 03:08 AM in reply to: SRSDS

Also try this code, not tested

        <CommandMethod("TestEntityJigger7")> _
        Public Shared Sub TestEntityJigger7_Method()
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
            Dim db As Database = HostApplicationServices.WorkingDatabase
            doc.TransactionManager.EnableGraphicsFlush(True)
            Dim pr As PromptResult = ed.GetString(vbLf & "Block name:")
            If pr.Status = PromptStatus.OK Then
                Using tr As Transaction = db.TransactionManager.StartTransaction()
                    Dim bt As BlockTable = TryCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
                    Dim btr As BlockTableRecord = TryCast(tr.GetObject(bt(pr.StringResult), OpenMode.ForRead), BlockTableRecord)
                    If btr IsNot Nothing Then
                        Dim br As New BlockReference(New Point3d(0, 0, 0), btr.ObjectId)
                        Dim pc As DynamicBlockReferencePropertyCollection = br.DynamicBlockReferencePropertyCollection
                        For i = 0 To pc.Count - 1
                            Dim prop As DynamicBlockReferenceProperty = pc(i)
                            If prop.PropertyName = "A" Then prop.Value = 1000.0#
                            If prop.PropertyName = "B" Then prop.Value = 2000.0#
                        Next
                        pc.Dispose()
                        tr.TransactionManager.QueueForGraphicsFlush()
                        If BlockMovingRotating.Jig(br) Then
                            Dim modelspace As BlockTableRecord = TryCast(tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)
                            modelspace.AppendEntity(br)
                            tr.AddNewlyCreatedDBObject(br, True)
                            tr.TransactionManager.QueueForGraphicsFlush()
                            doc.TransactionManager.FlushGraphics()
                            tr.Commit()

                        End If
                    End If
                End Using
            End If
        End Sub

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Mentor
SRSDS
Posts: 247
Registered: ‎04-15-2011
Message 4 of 9 (331 Views)

Re: Modify Dynamic Block Properties before Jig

06-11-2013 01:34 AM in reply to: Hallex

Hi Hallex,
It didn't seem to help. The dynamic grip points are not updated with the newly defined lengths.
And the properties palette
I can work around this by deleting the block reference and inserting a fresh one with the results from the jig.

The big problem is that I can't get the block to display properly for the jig in most cases.

Attached is an example.
Including a dimension change for the C parameter shows the problem.

                        If prop.PropertyName = "A" Then prop.Value = 1000.0#
                        If prop.PropertyName = "B" Then prop.Value = 2000.0#
                        If prop.PropertyName = "C" Then prop.Value = 3000.0#

If inserted without using a jig it seems to be fine, AutoCAD must analyse the constraints within a block more thoroughly and properly kick everything into position.

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 5 of 9 (325 Views)

Re: Modify Dynamic Block Properties before Jig

06-11-2013 03:10 AM in reply to: SRSDS
You have to append the new BlockTableRecord to the drawing and the current space before setting properties.
Mentor
SRSDS
Posts: 247
Registered: ‎04-15-2011
Message 6 of 9 (306 Views)

Re: Modify Dynamic Block Properties before Jig

06-11-2013 06:41 AM in reply to: DiningPhilosopher

Hi DiningPhilosopher,

 

I made that change. The jigged object is now inserted correctly (modified with grips in the correct place) but it's still not displaying the modified block within the jig (just the block definition). It is an improvement but hopeing there's a solution still.

 

 

        Using trans As Transaction = db.TransactionManager.StartTransaction()
            Dim bt As BlockTable = TryCast(trans.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
            Dim btr As BlockTableRecord = TryCast(trans.GetObject(bt(BlockName), OpenMode.ForRead), BlockTableRecord)
            If btr IsNot Nothing Then
                Dim br As New BlockReference(New Point3d(0, 0, 0), btr.ObjectId)
                Dim modelspace As BlockTableRecord = TryCast(trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)
                modelspace.AppendEntity(br)
                trans.AddNewlyCreatedDBObject(br, True)
                Dim pc As DynamicBlockReferencePropertyCollection = br.DynamicBlockReferencePropertyCollection
                For i = 0 To pc.Count - 1
                    Dim prop As DynamicBlockReferenceProperty = pc(i)
                    If prop.PropertyName = "A" Then prop.Value = 500.0#
                    If prop.PropertyName = "B" Then prop.Value = 500.0#
                    If prop.PropertyName = "C" Then prop.Value = 500.0#
                Next
                trans.TransactionManager.QueueForGraphicsFlush()
                doc.TransactionManager.FlushGraphics()
                If AcadNetAddinWizard_Namespace.BlockMovingRotating.Jig(br) Then
                End If
                trans.Commit()
            End If
        End Using

 

ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 7 of 9 (275 Views)

Re: Modify Dynamic Block Properties before Jig

06-12-2013 11:26 AM in reply to: SRSDS

You should set the DynamicBlockReferenceProperty's outside of your Transaction, after the commit.





Fenton Webb

Developer Technical Services

Autodesk Developer Network


Mentor
SRSDS
Posts: 247
Registered: ‎04-15-2011
Message 8 of 9 (268 Views)

Re: Modify Dynamic Block Properties before Jig

06-12-2013 12:49 PM in reply to: fenton.webb

Hi Fenton,

 

I'd like the modified block to display as modified before the jigging.

I've have tried modifying the blockreference within a seperate transaction and comitting it before the jig.

FlushGraphics doesn't seem to work.

FlushGraphics also shows  the block at the insertion point until after the jig.

No idea why I can't get this to work. 

 

ADN Support Specialist
Balaji_Ram
Posts: 692
Registered: ‎03-21-2011
Message 9 of 9 (239 Views)

Re: Modify Dynamic Block Properties before Jig

06-18-2013 01:27 AM in reply to: SRSDS

Hello,

 

This behavior seems specific to the drawing that you attached. I could not reproduce it with a simple dynamic block that I was using to test this behavior. I have attached a test drawing with the dynamic block that I created.

I may be missing some of the details of your dynamic block. 

 

A workaround in your case could be to have two custom commands. Not an elegant solution, but it worked ok with your drawing.

 

ObjectId _brefId = ObjectId.Null;

[CommandMethod("Test1")]
public void Test1()
{
    // Insert the block reference and set the parameters
    // Store the ObjectId of the block ref in _brefId

    // Call another command to jig the inserted block reference
    Application.DocumentManager.MdiActiveDocument.SendStringToExecute("Test2 ", false, false, false);
}
            
[CommandMethod("Test2")]
public void Test2()
{
   // Use _brefId to access the inserted block reference
   // Jig the block reference and set its transform
}

 

 

 

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

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.