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

Modify Dynamic Block Properties before Jig

8 REPLIES 8
Reply
Message 1 of 9
SRSDS
988 Views, 8 Replies

Modify Dynamic Block Properties before Jig

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

 

8 REPLIES 8
Message 2 of 9
Hallex
in reply to: SRSDS

Firstly, please remove the lines:
Else
tr.Abort()
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 9
Hallex
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
Message 4 of 9
SRSDS
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.

Message 5 of 9
DiningPhilosopher
in reply to: SRSDS

You have to append the new BlockTableRecord to the drawing and the current space before setting properties.
Message 6 of 9
SRSDS
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

 

Message 7 of 9
fenton.webb
in reply to: SRSDS

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




Fenton Webb
AutoCAD Engineering
Autodesk

Message 8 of 9
SRSDS
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. 

 

Message 9 of 9
Balaji_Ram
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

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