.NET

Reply
Mentor
Amremad
Posts: 217
Registered: ‎08-24-2010
Message 1 of 14 (245 Views)

Y Direction

245 Views, 13 Replies
06-25-2013 03:19 AM

i need to calculate the distance between two point in new ucs

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

Re : Y Direction

06-25-2013 05:57 AM in reply to: Amremad

Hi

 

The distance between 2 points is the same whatever the current UCS.

Gilles Chanteau
Mentor
Amremad
Posts: 217
Registered: ‎08-24-2010
Message 3 of 14 (231 Views)

Re : Y Direction

06-25-2013 05:59 AM in reply to: _gile

sorry i missed

 

i need to move the other point from any point in y direction

*Expert Elite*
_gile
Posts: 2,106
Registered: ‎04-29-2006
Message 4 of 14 (213 Views)

Re : Y Direction

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

To move an entity in the current UCS Y direction, you have to transform the y displacement vector with the current coodinate system before using this vector with the TransformBy() method.

 

Example to move the entity (ent) of 10 units in the UCS Y direction:

 

Vector3d disp = new Vector3d(0.0, 10.0, 0.0);
disp = disp.TransformBy(ed.CurrentUserCoordinateSystem);
ent.TransformBy(Matrix3d.Displacement(disp));

 

Gilles Chanteau
Mentor
Amremad
Posts: 217
Registered: ‎08-24-2010
Message 5 of 14 (187 Views)

Re : Y Direction

06-26-2013 02:03 AM in reply to: _gile

 

   Private Shared Sub ChangePostionLevel(MySelSet As SelectionSet, BPoint As Point3d, BValue As String)
        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

                If attRef.TextString > BValue Then
                    'NPoint = New Point3d(BlkRef.Position.X, (BPoint.Y + (Val(attRef.TextString) - Val(BValue)) ), BlkRef.Position.Z)

                    Dim distance As Double = ""
                ElseIf attRef.TextString < BValue Then
                    NPoint = New Point3d(BlkRef.Position.X, (BPoint.Y - (Val(BValue) - Val(attRef.TextString))), BlkRef.Position.Z)
                ElseIf attRef.TextString = BValue Then
               
                End If
                BlkRef.TransformBy(Matrix3d.Displacement(OPoint.GetVectorTo(NPoint)))
            Next
        End If
        Tr.Commit()
        Tr.Dispose()
    End Sub

 
this funciton work correctly with normal ucs (world mode) , but doesn't work with other ucs

see this picture to understand what i want

 

pic1.jpg

*Expert Elite*
_gile
Posts: 2,106
Registered: ‎04-29-2006
Message 6 of 14 (182 Views)

Re : Y Direction

06-26-2013 03:04 AM in reply to: Amremad

Hi,

 

If you read attentively my previous reply, you can see the displacement vector is transformed by Editor.CurrentCoordinateSystem before beeing passed to the TransformBy() method.

Gilles Chanteau
Mentor
Amremad
Posts: 217
Registered: ‎08-24-2010
Message 7 of 14 (179 Views)

Re : Y Direction

06-26-2013 03:12 AM in reply to: _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

                If attRef.TextString > BValue Then
                    NPoint = New Point3d(BlkRef.Position.X, (BPoint.Y + (Val(attRef.TextString) - Val(BValue)) * Unit), BlkRef.Position.Z)
                ElseIf attRef.TextString < BValue Then
                    NPoint = New Point3d(BlkRef.Position.X, (BPoint.Y - (Val(BValue) - Val(attRef.TextString)) * Unit), BlkRef.Position.Z)
                ElseIf attRef.TextString = BValue Then

                End If
                BlkRef.TransformBy(Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem)
                BlkRef.TransformBy(Matrix3d.Displacement(OPoint.GetVectorTo(NPoint)))
            Next
        End If
        Tr.Commit()
        Tr.Dispose()
    End Sub

 

like this ?????

 

it doens't work

Mentor
Amremad
Posts: 217
Registered: ‎08-24-2010
Message 8 of 14 (178 Views)

Re : Y Direction

06-26-2013 03:18 AM in reply to: Amremad

it's very hard , please help me , if you need completely code , i will send it to you

*Expert Elite*
_gile
Posts: 2,106
Registered: ‎04-29-2006
Message 9 of 14 (174 Views)

Re : Y Direction

06-26-2013 04:16 AM in reply to: Amremad

No, it is not "very hard", it's only some math logic.

 

You build a displacement vector from 2 points:

- the block reference insertion point (OPoint), BlockReference.Position returns a Point3d defined in WCS coordinates

- a point (NPoint) built from another one passed as argument to your function (BPoint)


The issue is: how is defined BPoint, WCS or UCS coordinates ?

 

If BPoint is defined in WCS coordinates, the displacement vector OPoint.GetVectorTo(Npoint) is defined too in WCS so you have to transform it:

Dim disp As Vector3d = OPoint.GetVectorTo(Npoint).TransformBy(ed.currentCoordinateSystem)

 

Esle if BPoint is defined in current UCS (as returned by Editor.GetPoint()), you have to transform OPoint from WCS to UCS before building the displacement vector. In this case, the displacement vector will be defined in UCS coordinates:

Dim disp As Vector3d = OPoint.TransformBy(ed.currentCoordinateSystem.Inverse()).GetVectorTo(Npoint)

 Then use this vector to Transform BlkRef...

Gilles Chanteau
Mentor
Amremad
Posts: 217
Registered: ‎08-24-2010
Message 10 of 14 (169 Views)

Re : Y Direction

06-26-2013 04:38 AM in reply to: _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

                If attRef.TextString > BValue Then
                    NPoint = New Point3d(BlkRef.Position.X, (BPoint.Y + (Val(attRef.TextString) - Val(BValue)) * Unit), BlkRef.Position.Z)
                ElseIf attRef.TextString < BValue Then
                    NPoint = New Point3d(BlkRef.Position.X, (BPoint.Y - (Val(BValue) - Val(attRef.TextString)) * Unit), BlkRef.Position.Z)
                ElseIf attRef.TextString = BValue Then

                End If
                Dim disp As Vector3d = OPoint.TransformBy(Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem.Inverse()).GetVectorTo(NPoint)
                BlkRef.TransformBy(Matrix3d.Displacement(disp))
            Next
        End If
        Tr.Commit()
        Tr.Dispose()

    End Sub

 also doesn't work

 

 

 

i think you will hit me :smileyhappy:

i think iam failure , i can't understand ,

 

if you need the completley code to fix it tell me and i will send it for you

 

iam so sorry

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.