<?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 Insert block in UCS with correct rotation in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/insert-block-in-ucs-with-correct-rotation/m-p/1679864#M33471</link>
    <description>When I try to insert a block using "InsertBlock" in VB6 and the current UCS is not WCS, the rotation of the block becames wrong, even if I trasform (transformby) the insertion point. &lt;BR /&gt;
&lt;BR /&gt;
How can I solve it ? Is it a Autocad bug ???&lt;BR /&gt;
&lt;BR /&gt;
I read all the messages about it in this forum but none had the answer...&lt;BR /&gt;
&lt;BR /&gt;
Thanks !!!&lt;BR /&gt;
&lt;BR /&gt;
Leonardo Roncetti</description>
    <pubDate>Mon, 19 Jun 2006 17:26:08 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2006-06-19T17:26:08Z</dc:date>
    <item>
      <title>Insert block in UCS with correct rotation</title>
      <link>https://forums.autodesk.com/t5/vba-forum/insert-block-in-ucs-with-correct-rotation/m-p/1679864#M33471</link>
      <description>When I try to insert a block using "InsertBlock" in VB6 and the current UCS is not WCS, the rotation of the block becames wrong, even if I trasform (transformby) the insertion point. &lt;BR /&gt;
&lt;BR /&gt;
How can I solve it ? Is it a Autocad bug ???&lt;BR /&gt;
&lt;BR /&gt;
I read all the messages about it in this forum but none had the answer...&lt;BR /&gt;
&lt;BR /&gt;
Thanks !!!&lt;BR /&gt;
&lt;BR /&gt;
Leonardo Roncetti</description>
      <pubDate>Mon, 19 Jun 2006 17:26:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/insert-block-in-ucs-with-correct-rotation/m-p/1679864#M33471</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-06-19T17:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: Insert block in UCS with correct rotation</title>
      <link>https://forums.autodesk.com/t5/vba-forum/insert-block-in-ucs-with-correct-rotation/m-p/1679865#M33472</link>
      <description>is it right if the WCS is current?&lt;BR /&gt;
&lt;BR /&gt;
&lt;LEORONCETTI&gt; wrote in message news:5211042@discussion.autodesk.com...&lt;BR /&gt;
When I try to insert a block using "InsertBlock" in VB6 and the current UCS &lt;BR /&gt;
is not WCS, the rotation of the block becames wrong, even if I trasform &lt;BR /&gt;
(transformby) the insertion point.&lt;BR /&gt;
&lt;BR /&gt;
How can I solve it ? Is it a Autocad bug ???&lt;BR /&gt;
&lt;BR /&gt;
I read all the messages about it in this forum but none had the answer...&lt;BR /&gt;
&lt;BR /&gt;
Thanks !!!&lt;BR /&gt;
&lt;BR /&gt;
Leonardo Roncetti&lt;/LEORONCETTI&gt;</description>
      <pubDate>Mon, 19 Jun 2006 18:37:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/insert-block-in-ucs-with-correct-rotation/m-p/1679865#M33472</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-06-19T18:37:43Z</dc:date>
    </item>
    <item>
      <title>Re: Insert block in UCS with correct rotation</title>
      <link>https://forums.autodesk.com/t5/vba-forum/insert-block-in-ucs-with-correct-rotation/m-p/1679866#M33473</link>
      <description>The InsertBlock method only works with WCS coordinates.  See help on the InsertBlock method.&lt;BR /&gt;
&lt;BR /&gt;
You may need to use the TranslateCoordinates method to get the proper WCS for your current UCS points.</description>
      <pubDate>Mon, 19 Jun 2006 19:19:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/insert-block-in-ucs-with-correct-rotation/m-p/1679866#M33473</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-06-19T19:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: Insert block in UCS with correct rotation</title>
      <link>https://forums.autodesk.com/t5/vba-forum/insert-block-in-ucs-with-correct-rotation/m-p/1679867#M33474</link>
      <description>You may need to adjust the .Normal vector of the BlockRef to get the rotation right if you aren't in WCS also.</description>
      <pubDate>Mon, 19 Jun 2006 19:23:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/insert-block-in-ucs-with-correct-rotation/m-p/1679867#M33474</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-06-19T19:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: Insert block in UCS with correct rotation</title>
      <link>https://forums.autodesk.com/t5/vba-forum/insert-block-in-ucs-with-correct-rotation/m-p/1679868#M33475</link>
      <description>When I try to adjust the .Normal vector, the block moves instead of rotating.&lt;BR /&gt;
&lt;BR /&gt;
When I apply the Transformby method the angle is not ok...</description>
      <pubDate>Tue, 20 Jun 2006 13:00:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/insert-block-in-ucs-with-correct-rotation/m-p/1679868#M33475</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-06-20T13:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: Insert block in UCS with correct rotation</title>
      <link>https://forums.autodesk.com/t5/vba-forum/insert-block-in-ucs-with-correct-rotation/m-p/1679869#M33476</link>
      <description>It would help if you posted your code....</description>
      <pubDate>Tue, 20 Jun 2006 13:46:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/insert-block-in-ucs-with-correct-rotation/m-p/1679869#M33476</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-06-20T13:46:28Z</dc:date>
    </item>
    <item>
      <title>Re: Insert block in UCS with correct rotation</title>
      <link>https://forums.autodesk.com/t5/vba-forum/insert-block-in-ucs-with-correct-rotation/m-p/1679870#M33477</link>
      <description>Does the insertion point move?  I'd  expect other portions of the block to move, because when you change the normal vector, you are&lt;BR /&gt;
rotating the objects about the insertion point, but the insertion point should not move.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;LEORONCETTI&gt; wrote in message news:5211894@discussion.autodesk.com...&lt;BR /&gt;
When I try to adjust the .Normal vector, the block moves instead of rotating.&lt;BR /&gt;
&lt;BR /&gt;
When I apply the Transformby method the angle is not ok...&lt;/LEORONCETTI&gt;</description>
      <pubDate>Tue, 20 Jun 2006 13:51:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/insert-block-in-ucs-with-correct-rotation/m-p/1679870#M33477</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-06-20T13:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: Insert block in UCS with correct rotation</title>
      <link>https://forums.autodesk.com/t5/vba-forum/insert-block-in-ucs-with-correct-rotation/m-p/1679871#M33478</link>
      <description>Here goes my code:&lt;BR /&gt;
......&lt;BR /&gt;
Set objBlock = moSpace.InsertBlock(pins, name_block, 1, 1, 1, 0) '' Pins is already tranformed to WCS&lt;BR /&gt;
  &lt;BR /&gt;
'' In the following code I tried to change de Normal vector&lt;BR /&gt;
''    Dim norm As Variant&lt;BR /&gt;
''    Dim nVec(x To Z) As Double&lt;BR /&gt;
''    nVec(0) = 0&lt;BR /&gt;
'' nVec(1) = 0&lt;BR /&gt;
'' nVec(2) = 1&lt;BR /&gt;
''    norm = objBlock.Normal&lt;BR /&gt;
''    objBlock.Normal = nVec&lt;BR /&gt;
&lt;BR /&gt;
    Set ucsObj = acadDoc.ActiveUCS   '' I´m using a UCS, not WCS&lt;BR /&gt;
    TransMatrix = ucsObj.GetUCSMatrix()&lt;BR /&gt;
    Call objBlock.TransformBy(TransMatrix)&lt;BR /&gt;
    Call objBlock.Update&lt;BR /&gt;
&lt;BR /&gt;
After this, the angle is completely different form the UCS....&lt;BR /&gt;
The insertion point is on the right position...

Message was edited by: LeoRoncetti</description>
      <pubDate>Tue, 20 Jun 2006 14:12:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/insert-block-in-ucs-with-correct-rotation/m-p/1679871#M33478</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-06-20T14:12:46Z</dc:date>
    </item>
    <item>
      <title>Re: Insert block in UCS with correct rotation</title>
      <link>https://forums.autodesk.com/t5/vba-forum/insert-block-in-ucs-with-correct-rotation/m-p/1679872#M33479</link>
      <description>Transforms work to make the angle correct also. See below.&lt;BR /&gt;
&lt;BR /&gt;
Sub Test()&lt;BR /&gt;
  CreateUCS&lt;BR /&gt;
&lt;BR /&gt;
  Dim pt1(0 To 2) As Double&lt;BR /&gt;
  pt1(0) = 0#: pt1(1) = 0#: pt1(2) = 0# 'WCS point&lt;BR /&gt;
&lt;BR /&gt;
  'Below insertion point and rotatation are in WCS&lt;BR /&gt;
  Dim myBlockRef As AcadBlockReference&lt;BR /&gt;
  Set myBlockRef = ThisDrawing.ModelSpace.InsertBlock(pt1, "Test", 1#, 1#, &lt;BR /&gt;
1#, 0#)&lt;BR /&gt;
&lt;BR /&gt;
  'Fix insertion to match current UCS&lt;BR /&gt;
  If ThisDrawing.GetVariable("UCSName") &amp;lt;&amp;gt; "" Then&lt;BR /&gt;
    Dim ucsMatrix As Variant&lt;BR /&gt;
    ucsMatrix = ThisDrawing.ActiveUCS.GetUCSMatrix&lt;BR /&gt;
&lt;BR /&gt;
    myBlockRef.TransformBy ucsMatrix&lt;BR /&gt;
  End If&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Private Sub CreateUCS()&lt;BR /&gt;
  Dim ucsOrg(0 To 2) As Double&lt;BR /&gt;
  ucsOrg(0) = 3#: ucsOrg(1) = 3#: ucsOrg(2) = 3# 'WCS point&lt;BR /&gt;
&lt;BR /&gt;
  With ThisDrawing.Utility&lt;BR /&gt;
    Dim ucsXPt As Variant&lt;BR /&gt;
    ucsXPt = .PolarPoint(ucsOrg, .AngleToReal("45", acDegrees), 1#) 'vector&lt;BR /&gt;
&lt;BR /&gt;
    Dim ucsYPt As Variant&lt;BR /&gt;
    ucsYPt = .PolarPoint(ucsOrg, .AngleToReal("135", acDegrees), 1#) 'vector&lt;BR /&gt;
  End With&lt;BR /&gt;
&lt;BR /&gt;
  Dim myUCS As AcadUCS&lt;BR /&gt;
  Set myUCS = ThisDrawing.UserCoordinateSystems.Add(ucsOrg, ucsXPt, ucsYPt, &lt;BR /&gt;
"Test")&lt;BR /&gt;
&lt;BR /&gt;
  ThisDrawing.ActiveUCS = myUCS&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
R. Robert Bell&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;LEORONCETTI&gt; wrote in message news:5212095@discussion.autodesk.com...&lt;BR /&gt;
Here goes my code:&lt;BR /&gt;
......&lt;BR /&gt;
Set objBlock = moSpace.InsertBlock(pins, name_block, 1, 1, 1, 0) '' Pins is &lt;BR /&gt;
already tranformed to WCS&lt;BR /&gt;
&lt;BR /&gt;
'' In the following code I tried to change de Normal vector&lt;BR /&gt;
''    Dim norm As Variant&lt;BR /&gt;
''    Dim nVec(x To Z) As Double&lt;BR /&gt;
''    nVec(0) = 0&lt;BR /&gt;
'' nVec(1) = 0&lt;BR /&gt;
'' nVec(2) = 1&lt;BR /&gt;
''    norm = objBlock.Normal&lt;BR /&gt;
''    objBlock.Normal = nVec&lt;BR /&gt;
&lt;BR /&gt;
    Set ucsObj = acadDoc.ActiveUCS   '' I´m using a UCS, not WCS&lt;BR /&gt;
    TransMatrix = ucsObj.GetUCSMatrix()&lt;BR /&gt;
    Call objBlock.TransformBy(TransMatrix)&lt;BR /&gt;
    Call objBlock.Update&lt;BR /&gt;
&lt;BR /&gt;
After this, the angle is completely different form the UCS....&lt;BR /&gt;
The insertion point is on the right position...&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: LeoRoncetti&lt;/LEORONCETTI&gt;</description>
      <pubDate>Tue, 20 Jun 2006 16:41:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/insert-block-in-ucs-with-correct-rotation/m-p/1679872#M33479</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-06-20T16:41:15Z</dc:date>
    </item>
    <item>
      <title>Re: Insert block in UCS with correct rotation</title>
      <link>https://forums.autodesk.com/t5/vba-forum/insert-block-in-ucs-with-correct-rotation/m-p/1679873#M33480</link>
      <description>I guess I'm not sure what you want.  Do you want the block's rotation to change when you jump to the UCS?&lt;BR /&gt;
&lt;BR /&gt;
I was experimenting with the following code, which seems to rotate the block to the UCS plane, but keeps the original insertion&lt;BR /&gt;
point.&lt;BR /&gt;
&lt;BR /&gt;
  Sub Example_GetUCSMatrix()&lt;BR /&gt;
    ' This example creates a new UCS and finds the UCS matrix for it.&lt;BR /&gt;
    ' It then creates a circleblock using WCS coordinates and&lt;BR /&gt;
    ' transforms the circle for the UCS.&lt;BR /&gt;
&lt;BR /&gt;
    ' Define a new UCS and turn on the UCS icon at the origin.&lt;BR /&gt;
    Dim ucsObj As AcadUCS&lt;BR /&gt;
    Dim origin(0 To 2) As Double&lt;BR /&gt;
    Dim xAxisPoint(0 To 2) As Double&lt;BR /&gt;
    Dim yAxisPoint(0 To 2) As Double&lt;BR /&gt;
&lt;BR /&gt;
    origin(0) = 2: origin(1) = 2: origin(2) = 0&lt;BR /&gt;
    xAxisPoint(0) = 3: xAxisPoint(1) = 2: xAxisPoint(2) = 0&lt;BR /&gt;
    yAxisPoint(0) = 2: yAxisPoint(1) = 3: yAxisPoint(2) = 4&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
  ' Create the block&lt;BR /&gt;
    Dim blockObj As AcadBlock&lt;BR /&gt;
    Dim insertionPnt(0 To 2) As Double&lt;BR /&gt;
    insertionPnt(0) = 0#: insertionPnt(1) = 0#: insertionPnt(2) = 0#&lt;BR /&gt;
    Set blockObj = ThisDrawing.Blocks.Add(insertionPnt, "CircleBlock")&lt;BR /&gt;
&lt;BR /&gt;
    ' Add a circle to the block&lt;BR /&gt;
    Dim circleObj As AcadCircle, lineObj As AcadLine&lt;BR /&gt;
    Dim center(0 To 2) As Double&lt;BR /&gt;
    Dim radius As Double&lt;BR /&gt;
    center(0) = 0: center(1) = 0: center(2) = 0&lt;BR /&gt;
    radius = 1&lt;BR /&gt;
    Set circleObj = blockObj.AddCircle(center, radius)&lt;BR /&gt;
    Set lineObj = blockObj.AddLine(center, yAxisPoint)&lt;BR /&gt;
    Set lineObj = blockObj.AddLine(center, xAxisPoint)&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
    insertionPnt(0) = 2#: insertionPnt(1) = 2#: insertionPnt(2) = 0&lt;BR /&gt;
    'Insert the block twice at the same point&lt;BR /&gt;
    Dim blockRefObj0 As AcadBlockReference, blockRefObj1 As AcadBlockReference&lt;BR /&gt;
&lt;BR /&gt;
    Set blockRefObj0 = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, "CircleBlock", 1#, 1#, 1#, 0)&lt;BR /&gt;
    Set blockRefObj1 = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, "CircleBlock", 1#, 1#, 1#, 0)&lt;BR /&gt;
&lt;BR /&gt;
    'Create the new UCS&lt;BR /&gt;
    ThisDrawing.SendCommand "ucsfollow 1 "&lt;BR /&gt;
    Set ucsObj = ThisDrawing.UserCoordinateSystems.Add(origin, xAxisPoint, yAxisPoint, "UCS1")&lt;BR /&gt;
    ThisDrawing.ActiveUCS = ucsObj&lt;BR /&gt;
    ThisDrawing.ActiveViewport.UCSIconOn = True&lt;BR /&gt;
    ThisDrawing.ActiveViewport.UCSIconAtOrigin = True&lt;BR /&gt;
    ThisDrawing.ActiveViewport = ThisDrawing.ActiveViewport&lt;BR /&gt;
&lt;BR /&gt;
     ' Get the UCS transformation matrix&lt;BR /&gt;
    Dim TransMatrix As Variant&lt;BR /&gt;
    TransMatrix = ucsObj.GetUCSMatrix()&lt;BR /&gt;
&lt;BR /&gt;
   ' Transform the circle to the UCS coordinates&lt;BR /&gt;
&lt;BR /&gt;
    blockRefObj1.TransformBy (TransMatrix)&lt;BR /&gt;
    blockRefObj1.InsertionPoint = insertionPnt&lt;BR /&gt;
    blockRefObj1.Update&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
End Sub</description>
      <pubDate>Tue, 20 Jun 2006 16:57:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/insert-block-in-ucs-with-correct-rotation/m-p/1679873#M33480</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-06-20T16:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: Insert block in UCS with correct rotation</title>
      <link>https://forums.autodesk.com/t5/vba-forum/insert-block-in-ucs-with-correct-rotation/m-p/1679874#M33481</link>
      <description>Hello Leonardo,&lt;BR /&gt;
&lt;BR /&gt;
Maybe a bit late, but I was struggling with the same problem just now...&lt;BR /&gt;
&lt;BR /&gt;
I solved the mystery !&lt;BR /&gt;
&lt;BR /&gt;
My programming background is Delphi, that's why I will not write VBA code.&lt;BR /&gt;
&lt;BR /&gt;
When inserting a blockreference it will always be placed at the coordinates you provide in WCS, its orientation however is in UCS! When using this method there is no need to switch between UCS and WCS every time.&lt;BR /&gt;
&lt;BR /&gt;
A transformation with the UCS-matrix will NOT work because your insertion point is not in UCS...&lt;BR /&gt;
&lt;BR /&gt;
What you'll have to do is:&lt;BR /&gt;
1) move the block to the origin with&lt;BR /&gt;
    - define a matrix for translation: -x,-y,-z&lt;BR /&gt;
    -  transformby(transMatrix)&lt;BR /&gt;
2) now align the orientation to the WCS&lt;BR /&gt;
    - get the OCS-matrix, this is the UCS-matrix without the translation part&lt;BR /&gt;
    - transformby(inverted(OCS-matrix))&lt;BR /&gt;
3) move the block to its insertionpoint&lt;BR /&gt;
    - define a matrix for translation: x,y,z&lt;BR /&gt;
    -  transformby(transMatrix)&lt;BR /&gt;
&lt;BR /&gt;
Tadaaa&lt;BR /&gt;
&lt;BR /&gt;
Hope this can still help you ;o)</description>
      <pubDate>Fri, 17 Nov 2006 14:47:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/insert-block-in-ucs-with-correct-rotation/m-p/1679874#M33481</guid>
      <dc:creator>JackHouben</dc:creator>
      <dc:date>2006-11-17T14:47:40Z</dc:date>
    </item>
  </channel>
</rss>

