.NET

Reply
*Expert Elite*
_gile
Posts: 2,078
Registered: ‎04-29-2006
Message 11 of 14 (145 Views)

Re : Y Direction

06-26-2013 06:25 AM in reply to: Amremad

From your last code, it seems to me that what you want to do is move the block reference about the current UCS Y axis with a value which is equal to:

BPoint.Y + (Val(attRef.TextString) - Val(BValue)) * Unit

 Try the code below (I remove some unuseful statements)

        Private Shared Sub ChangePostionLevel(MySelSet As SelectionSet, BPoint As Point3d, BValue As String, Unit As Double)

            Using Tr As Transaction = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction()
                If MySelSet IsNot Nothing Then
                    For Each BlKID In MySelSet.GetObjectIds()

                        Dim BlkRef As BlockReference = Tr.GetObject(BlKID, OpenMode.ForWrite)
                        Dim objId As ObjectId = BlkRef.AttributeCollection.Item(0)
                        Dim attRef As AttributeReference = Tr.GetObject(objId, OpenMode.ForRead)

                        Dim yVal As Double = BPoint.Y + (Val(attRef.TextString) - Val(BValue)) * Unit
                        Dim disp As Vector3d = New Vector3d(0.0, yVal, 0.0)
                        disp = disp.TransformBy(Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem)
                        BlkRef.TransformBy(Matrix3d.Displacement(disp))
                    Next
                End If
                Tr.Commit()
            End Using

        End Sub

 

Gilles Chanteau
Mentor
Amremad
Posts: 212
Registered: ‎08-24-2010
Message 12 of 14 (141 Views)

Re : Y Direction

06-26-2013 06:37 AM in reply to: _gile

know i know where is the problem

 

this is my correct code mr _gile

    Private Shared Sub ChangePostionLevel(MySelSet As SelectionSet, BPoint As Point3d, BValue As String, Unit As Double)
        Dim Tr As Transaction = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction()
        If MySelSet IsNot Nothing Then
            For Each BlKID In MySelSet.GetObjectIds()

                Dim BlkRef As BlockReference = Tr.GetObject(BlKID, OpenMode.ForWrite)
                Dim objId As ObjectId = BlkRef.AttributeCollection.Item(0)
                Dim attRef As AttributeReference = Tr.GetObject(objId, OpenMode.ForWrite)

                Dim OPoint As Point3d = New Point3d(BlkRef.Position.X, BlkRef.Position.Y, BlkRef.Position.Z)
                ' Dim NPoint As Point3d


                Dim TDistance As Double = Math.Abs(BlkRef.Position.Y - BPoint.Y)
                Dim FDistance As Double

                If Val(attRef.TextString) > BValue Then
                    Dim PDistance As Double = (Val(attRef.TextString) - Val(BValue)) * Unit
                    If TDistance > PDistance Then
                        FDistance = -(TDistance - (PDistance))
                    Else
                        FDistance = TDistance + (PDistance)
                    End If
                ElseIf Val(attRef.TextString) < BValue Then
                    Dim PDistance As Double = (Val(attRef.TextString) - Val(BValue)) * Unit
                    If TDistance > PDistance Then
                        FDistance = TDistance + (PDistance)
                    Else
                        FDistance = TDistance - (PDistance)
                    End If
                Else
                End If

                Dim disp As Vector3d = New Vector3d(0.0, FDistance, 0.0)
                disp = disp.TransformBy(Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem)
                BlkRef.TransformBy(Matrix3d.Displacement(disp))


            Next
        End If
        Tr.Commit()
        Tr.Dispose()
    End Sub

 in the red line , the distance between block and base point in WCS , no problem

but when the code can't calcualte the distance in UCS  Correctly

 

so how can i get the distance between two point in any UCS or WCS Correctly

 

understand me

*Expert Elite*
_gile
Posts: 2,078
Registered: ‎04-29-2006
Message 13 of 14 (136 Views)

Re : Y Direction

06-26-2013 07:05 AM in reply to: Amremad

It's really difficult to help you if the problem data changes with each message...

 

As I said, the BlockReference.Position is always defined in WCS coordinates, so if the 'BPoint' is not defined in WCS coordinates, you have to transform one of both so that they're defined in the same coordinate system before getting the distance between them.

The rest of your arithmetic could be simplified which would make the code more readable.

Gilles Chanteau
Mentor
Amremad
Posts: 212
Registered: ‎08-24-2010
Message 14 of 14 (116 Views)

Re : Y Direction

06-27-2013 02:58 AM in reply to: _gile

It's really difficult to help you if the problem data changes with each message...

 

iam so sorry , but i work hard with this code:smileyhappy:

iam sorry

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

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 to get help installing your software.

Ask the Community