<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Insert block and matrix transform it to p1 and p2 possition problem... in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/insert-block-and-matrix-transform-it-to-p1-and-p2-possition/m-p/5883525#M38179</link>
    <description>&lt;P&gt;I want to insert a block(almost only a straight line) at p1 and rotate/transform it so it points to p2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In VB I&amp;nbsp;set a new ucs between the points and inserted the block.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://forums.autodesk.com/t5/image/serverpage/image-id/197269iFCB70CD6DF57989E/image-size/large?v=mpbl-1&amp;amp;px=-1" border="0" alt="Untitled-1.png" title="Untitled-1.png" /&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Oct 2015 11:01:29 GMT</pubDate>
    <dc:creator>jokiller70</dc:creator>
    <dc:date>2015-10-29T11:01:29Z</dc:date>
    <item>
      <title>Insert block and matrix transform it to p1 and p2 possition problem...</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-block-and-matrix-transform-it-to-p1-and-p2-possition/m-p/5877781#M38175</link>
      <description>&lt;P&gt;I want to insert a block and rotate it to 2 points that i select in modelspace. But i get eCannotScaleNonUniformly with this code;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;                        Dim acPt3d As Point3d = New Point3d(0, 0, 0)
                        Dim acVec3d As Vector3d = acPt3d.GetVectorTo(p1)
                        blockRef.TransformBy(Matrix3d.Displacement(acVec3d))
                        Dim zAxis As Vector3d = curUCS.Zaxis
                        Dim xAxis As Vector3d = p1.GetVectorTo(p2).GetNormal
                        Dim yAxis As Vector3d
                        If xAxis.IsEqualTo(zAxis) Then
                            yAxis = curUCS.Yaxis
                            zAxis = xAxis.CrossProduct(yAxis).GetNormal
                        Else
                            yAxis = zAxis.CrossProduct(xAxis).GetNormal
                        End If
                        blockRef.TransformBy(New Matrix3d(New Double() {xAxis.X, yAxis.X, zAxis.X, p1.X, xAxis.Y, yAxis.Y, zAxis.Y, p1.Y, xAxis.Z, yAxis.Z, zAxis.Z, p1.Z, 0, 0, 0, 1}))
 &lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Oct 2015 11:55:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-block-and-matrix-transform-it-to-p1-and-p2-possition/m-p/5877781#M38175</guid>
      <dc:creator>jokiller70</dc:creator>
      <dc:date>2015-10-26T11:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: Insert block and matrix transform it to p1 and p2 possition problem...</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-block-and-matrix-transform-it-to-p1-and-p2-possition/m-p/5877864#M38176</link>
      <description>&lt;P&gt;Your Matrix probably contains a scale factor (not all Vectors seems to be normals)...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here should be a solution for your problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://adndevblog.typepad.com/autocad/2012/08/remove-scaling-from-transformation-matrix.html" target="_blank"&gt;http://adndevblog.typepad.com/autocad/2012/08/remove-scaling-from-transformation-matrix.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2015 12:50:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-block-and-matrix-transform-it-to-p1-and-p2-possition/m-p/5877864#M38176</guid>
      <dc:creator>Matti72</dc:creator>
      <dc:date>2015-10-26T12:50:13Z</dc:date>
    </item>
    <item>
      <title>Re: Insert block and matrix transform it to p1 and p2 possition problem...</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-block-and-matrix-transform-it-to-p1-and-p2-possition/m-p/5883381#M38177</link>
      <description>&lt;P&gt;Still same problem...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Dim mx As Matrix3d = New Matrix3d(New Double() {xAxis.X, yAxis.X, zAxis.X, p1.X, xAxis.Y, yAxis.Y, zAxis.Y, p1.Y, xAxis.Z, yAxis.Z, zAxis.Z, p1.Z, 0, 0, 0, 1})
                        Dim axes As New List(Of Vector3d)

                        For i As Integer = 0 To 2
                            Dim vec As New Vector3d(mx(i, 0), mx(i, 1), mx(i, 2))
                            vec = vec.GetNormal()
                            axes.Add(vec)
                        Next

                        Dim mx2 As Matrix3d = New Matrix3d(New Double() _
                        {
                          axes(0).X, axes(0).Y, axes(0).Z, mx(0, 3),
                          axes(1).X, axes(1).Y, axes(1).Z, mx(1, 3),
                          axes(2).X, axes(2).Y, axes(2).Z, mx(2, 3),
                          mx(3, 0), mx(3, 1), mx(3, 2), mx(3, 3)
                        })

                        blockRef.TransformBy(mx2)&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Oct 2015 09:01:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-block-and-matrix-transform-it-to-p1-and-p2-possition/m-p/5883381#M38177</guid>
      <dc:creator>jokiller70</dc:creator>
      <dc:date>2015-10-29T09:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: Insert block and matrix transform it to p1 and p2 possition problem...</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-block-and-matrix-transform-it-to-p1-and-p2-possition/m-p/5883461#M38178</link>
      <description>from your initial description and this last code, I'm not sure what you want to achieve here...&lt;BR /&gt;&lt;BR /&gt;can you try add an image to this thread showing what you want?</description>
      <pubDate>Thu, 29 Oct 2015 10:14:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-block-and-matrix-transform-it-to-p1-and-p2-possition/m-p/5883461#M38178</guid>
      <dc:creator>augusto.goncalves</dc:creator>
      <dc:date>2015-10-29T10:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: Insert block and matrix transform it to p1 and p2 possition problem...</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-block-and-matrix-transform-it-to-p1-and-p2-possition/m-p/5883525#M38179</link>
      <description>&lt;P&gt;I want to insert a block(almost only a straight line) at p1 and rotate/transform it so it points to p2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In VB I&amp;nbsp;set a new ucs between the points and inserted the block.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://forums.autodesk.com/t5/image/serverpage/image-id/197269iFCB70CD6DF57989E/image-size/large?v=mpbl-1&amp;amp;px=-1" border="0" alt="Untitled-1.png" title="Untitled-1.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2015 11:01:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-block-and-matrix-transform-it-to-p1-and-p2-possition/m-p/5883525#M38179</guid>
      <dc:creator>jokiller70</dc:creator>
      <dc:date>2015-10-29T11:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: Insert block and matrix transform it to p1 and p2 possition problem...</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-block-and-matrix-transform-it-to-p1-and-p2-possition/m-p/5883672#M38180</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IMO, the most easier way is to define your block as a line along Z axis (e.g. from 0,0,0 to 0,0,1) and then, just use a plane which origin is the base point and the normal the vector from the base point to the second one to transform the block.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("test")]
        public void Test()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            var options = new PromptPointOptions("\nBase point: ");
            var result = ed.GetPoint(options);
            if (result.Status != PromptStatus.OK)
                return;
            var basePt = result.Value;

            options.Message = "\nDirection point: ";
            options.BasePoint = basePt;
            options.UseBasePoint = true;
            result = ed.GetPoint(options);
            if (result.Status != PromptStatus.OK)
                return;
            var dirPt = result.Value;

            var ucs = ed.CurrentUserCoordinateSystem;
            basePt = basePt.TransformBy(ucs);
            dirPt = dirPt.TransformBy(ucs);

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); 

                var plane = new Plane(basePt, basePt.GetVectorTo(dirPt));

                var br = new BlockReference(Point3d.Origin, bt["test"]);
                br.TransformBy(Matrix3d.PlaneToWorld(plane));
                curSpace.AppendEntity(br);
                tr.AddNewlyCreatedDBObject(br, true);
                tr.Commit();
            }
        }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2015 12:40:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-block-and-matrix-transform-it-to-p1-and-p2-possition/m-p/5883672#M38180</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2015-10-29T12:40:29Z</dc:date>
    </item>
  </channel>
</rss>

