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

Selecting and Moving grips on dynamic blocks?

11 REPLIES 11
Reply
Message 1 of 12
geeThanks
119453 Views, 11 Replies

Selecting and Moving grips on dynamic blocks?

I apologize if this has been answered before, I took the time to search and was unable to find anything that seemed relevant. I have also had trouble figuring out the documentation.

 

Is there a way to select a specific grip within a dynamic block and then update its position?

Would some one be kind enough to share an example, or point me in the right direction?

 

Thanks!

Tags (2)
11 REPLIES 11
Message 2 of 12
geeThanks
in reply to: geeThanks

This is what I am trying currently.

 

public void MoveGrip(Point3d gripPoint, Vector3d offset)
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Transaction tr = db.TransactionManager.StartTransaction();
            using (tr)
            {
                BlockReference br = null;
                Entity ent = (Entity)tr.GetObject(_oBlockRefId, OpenMode.ForWrite);
                br = ent as BlockReference;
                if(br != null)
                {
                    GripDataCollection grips = new GripDataCollection();
                    GripDataCollection updateGrip = new GripDataCollection();
                    double curViewUnitSize = 0;
                    int gripSize = 0;
                    Vector3d curViewDir = doc.Editor.GetCurrentView().ViewDirection;
                    GetGripPointsFlags bitFlags = GetGripPointsFlags.GripPointsOnly;
                    br.GetGripPoints(grips, curViewUnitSize, gripSize, curViewDir, bitFlags);
                    foreach (GripData grip in grips)
                    {
                        if (grip.GripPoint == gripPoint)
                        {
                            updateGrip.Add(grip);
                        }
                    }
                    br.MoveGripPointsAt(updateGrip, offset, MoveGripPointsFlags.Polar);
                }
            }
        }

 Stepping through it, it looks like I do get a collection of points, and one does match with the position passed in.

What does not work is "MoveGripPointsAt", I have tried using the different enums available. No luck so far.

 

 

Message 3 of 12
geeThanks
in reply to: geeThanks

Just to clarify what I am trying to accomplish,

I have pipes that need to be streched and rotated to have their ends pined to a specified point.

I can manually select the polar grip and pin it to the point.

What I want is to avoid having to calculate the angles and strech values.

Some of the dynamic blocks have different property names, some rotations are offset, and some blocks are inverted.

 

Please any suggestions would be much appreciated.

Message 4 of 12
geeThanks
in reply to: geeThanks

Im being told its not possible to get a grip, and update its postition? I find it hard to believe.

Would really appreciate some some input.

 

Trying to find any information on GetGripData, and MoveGripPointsAt has been a huge pain.

I feel like It should not be this difficult.

 

This looks like its the only documentation out there, http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html

Message 5 of 12
geeThanks
in reply to: geeThanks

Anybody out there?

Message 6 of 12
geeThanks
in reply to: geeThanks

bump

Message 7 of 12

There is only one documented way of modifying dynamic blocks - ObjectARX SDK Docs-> Dynamic Blocks, Protocol Reactors, and Evaluation Graphs-> Dynamic Block API

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 8 of 12
nathan307
in reply to: geeThanks

Dear Friend....

     I tried to create a pipe by using AcDb3dSolid in ObjectArx by C++.But I cant set grip points to that pipe

     I Want To Create a Pipe(in 3dSolid As like a Cylinder in 3d Solid) between Two Points...

     Then how to set grip Points to the pipe...

     How to crete it as a Dynamic Block.

     Please Give Your Suggestion....

     

    Thank you Friend...

  

     With regards..

     nathan307

Message 9 of 12
WolframKuss12
in reply to: nathan307

Please have a look at grip overrules, that is one way to do it. Google will find some texts about it. AFAIK custom entities would be another way. I am a newbie at AutoCAd programming and dont know about dynamic blocks.

 

This is the .NET forum, there is also an objectArx forum.

Message 10 of 12
dnxk
in reply to: geeThanks

Hi, have you found the solution to change the position of grips with code? now i'm stuck with the same problem. It seems quite simple, but so hard to achieve...

great thanks to anyone who can help

Message 11 of 12
SRSDS
in reply to: dnxk

    Public Sub ChangeDybpropValue(objID As ObjectId, ByRef trans As Transaction, ByVal sPropertyName As String, ByVal Value As Object)
        Using br As BlockReference = DirectCast(trans.GetObject(objID, OpenMode.ForWrite), BlockReference)
            Using pc As DynamicBlockReferencePropertyCollection = br.DynamicBlockReferencePropertyCollection
                For i As Integer = 0 To pc.Count - 1
                    Dim prop As DynamicBlockReferenceProperty = pc(i)
                    If prop.PropertyName.ToUpper = sPropertyName.ToUpper Then
                        prop.Value = Value
                        Exit For
                    End If
                Next
            End Using
        End Using
    End Sub
Message 12 of 12
d_prontnicki
in reply to: geeThanks

@geeThanks 

 

Hi I am utilizing your move grip point method, which is genius by the way. What I cant figure out is how did you compensate for the block rotation? I am using this to align dynamic block "callouts" (Dynamic Mleaders) I use the following to get the move to location: (the position under the first callout (selectedReferenceCallOut)).

 

Private Function GetMoveToPoint3d(ByVal selectedReferenceCallOut As ObjectId) As Point3d

        Dim moveToPoint3d As Point3d
        Dim moveToPoint3dX As Double
        Dim moveToPoint3dY As Double

        Try

            Using acDocumentLock As DocumentLock = Active.Document.LockDocument()

                Using acTranaction As Transaction = Active.Database.TransactionManager.StartTransaction()

                    Dim dviewangle = GetCurrentDviewAngle()

                    Dim acBlockReference As BlockReference = CType(acTranaction.GetObject(selectedReferenceCallOut, OpenMode.ForRead), BlockReference)

                    '------------------------- Get X Position -------------------------
                    Dim acGripDataCollection As New GripDataCollection()
                    Dim currentViewUnitSize As Double = 0
                    Dim gripSize As Integer = 0
                    Dim currentViewVector3d As Vector3d = acCurrentDocument.Editor.GetCurrentView().ViewDirection
                    Dim bitFlags As GetGripPointsFlags = GetGripPointsFlags.GripPointsOnly

                    acBlockReference.GetGripPoints(acGripDataCollection, currentViewUnitSize, gripSize, currentViewVector3d, bitFlags)

                    moveToPoint3dX = acGripDataCollection(1).GripPoint.RotateBy(acBlockReference.Rotation, Vector3d.ZAxis, acBlockReference.Position).X

                    '------------------------- Get Y Position -------------------------

                    For Each acAttributeOjectId As ObjectId In acBlockReference.AttributeCollection

                        Dim acAttributeReference = CType(acTranaction.GetObject(acAttributeOjectId, OpenMode.ForRead), AttributeReference)

                        If acAttributeReference.Tag = "INSTALL" Then

                            If acAttributeReference.MTextAttribute.Visible = False Then

                                moveToPoint3dY = acAttributeReference.MTextAttribute.GeometricExtents.MinPoint.RotateBy(acBlockReference.Rotation, Vector3d.ZAxis, acBlockReference.Position).Y + 0.16 ' - acBlockReference.Rotation

                            Else

                                moveToPoint3dY = acAttributeReference.MTextAttribute.GeometricExtents.MinPoint.RotateBy(acBlockReference.Rotation, Vector3d.ZAxis, acBlockReference.Position).Y ' - acBlockReference.Rotation

                            End If

                        End If

                        Exit For

                    Next

                    moveToPoint3d = New Point3d(moveToPoint3dX, moveToPoint3dY, 0)

                    acTranaction.Commit()

                End Using

            End Using

            Return moveToPoint3d

        Catch ex As Exception

            MessageServices.DisplayError("Error Reading Block!", "Could not extract point X and Y positions.", ex)

            Return Nothing

        End Try

    End Function

 

And the following to move the the other callouts (selectedCallOutsToMove) to the above move to location... It would move the first one, commit it, and then use the GetMoveToPoint3d on the callout just committed and continue that for each  selectedCallOutsToMove. (Iteration left out of code for now as I am just trying to get it to work on one for now.)

 

Private Sub MoveSelectedCallOuts(ByVal selectedReferenceCallOut As ObjectId, ByVal selectedReferenceCallOutPosition As Point3d, ByVal selectedCallOutsToMove As SelectionSet)

        Try

            Using acDocumentLock As DocumentLock = Active.Document.LockDocument()

                Using acTranaction As Transaction = Active.Database.TransactionManager.StartTransaction()

                    Dim dviewangle = GetCurrentDviewAngle()

                    For Each selectedCallOut In selectedCallOutsToMove

                        If selectedCallOut.ObjectId <> selectedReferenceCallOut Then

                            Dim callOutEntity As Entity = CType(acTranaction.GetObject(selectedCallOut.ObjectId, OpenMode.ForWrite), Entity)
                            Dim acBlockReference As BlockReference = TryCast(callOutEntity, BlockReference)

                            Dim acGripDataCollection As New GripDataCollection()
                            Dim updateGrip As New GripDataCollection()
                            Dim currentViewUnitSize As Double = 0
                            Dim gripSize As Integer = 0
                            Dim currentViewVector3d As Vector3d = acCurrentDocument.Editor.GetCurrentView().ViewDirection
                            Dim bitFlags As GetGripPointsFlags = GetGripPointsFlags.GripPointsOnly

                            acBlockReference.GetGripPoints(acGripDataCollection, currentViewUnitSize, gripSize, currentViewVector3d, bitFlags)

                            updateGrip.Add(acGripDataCollection(1))

                            Dim adjustedGripPointLocation = acGripDataCollection(1).GripPoint.RotateBy(acBlockReference.Rotation, Vector3d.ZAxis, acBlockReference.Position)

                            Dim newMoveToVectors = adjustedGripPointLocation.GetVectorTo(selectedReferenceCallOutPosition)
                            acBlockReference.MoveGripPointsAt(updateGrip, newMoveToVectors, MoveGripPointsFlags.Polar)


                        End If

                    Next

                    acTranaction.Commit()

                End Using

            End Using

        Catch ex As Exception

            MessageServices.DisplayError("Error Moving Call Outs!", "Please contact the CADD Department for help.", ex)

        End Try

    End Sub

 

It works great when the block is not rotated. I used the Rotate by to compensate for the block rotation and it gets it close but to the exact position. 

image (1).png

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