[VBA]如何得到当前文档的当前无名ucs的转换矩阵?
本帖最后由 作者 于 2006-9-19 14:39:20 编辑rt <P>autodesk的代码如下,按照原理应该可行,可惜坐标转换之后保存的OriginalUCS有错误。郁闷啊。</P>
<P>Sub Example_ActiveUCS1()<BR> ' This example returns the current saved UCS (or saves a new one dynamically)<BR> ' and then sets a new UCS.<BR> ' Finally, it returns the UCS to the previous setting.<BR> <BR> Dim newUCS As AcadUCS<BR> Dim currUCS As AcadUCS<BR> Dim origin(0 To 2) As Double<BR> Dim xAxis(0 To 2) As Double<BR> Dim yAxis(0 To 2) As Double<BR> Dim pnt As Variant<BR> ' Get the current saved UCS of the active document. If the current UCS is<BR> ' not saved, then add a new UCS to the UserCoordinateSystems collection<BR> If ThisDrawing.GetVariable("UCSNAME") = "" Then<BR> ' Current UCS is not saved so get the data and save it<BR> With ThisDrawing<BR> Set currUCS = .UserCoordinateSystems.Add( _<BR> .GetVariable("UCSORG"), _<BR> .Utility.TranslateCoordinates(.GetVariable("UCSXDIR"), acUCS, acWorld, 0), _<BR> .Utility.TranslateCoordinates(.GetVariable("UCSYDIR"), acUCS, acWorld, 0), _<BR> "OriginalUCS")<BR> End With<BR> Else<BR> Set currUCS = ThisDrawing.ActiveUCS 'current UCS is saved<BR> End If<BR>' .Utility.TranslateCoordinates(.GetVariable("UCSXDIR"), acUCS, acWorld, 0), _<BR>' .Utility.TranslateCoordinates(.GetVariable("UCSYDIR"), acUCS, acWorld, 0), _</P>
<P> <BR>'<BR>pnt = ThisDrawing.GetVariable("UCSORG")</P>
<P> Debug.Print pnt(0); pnt(1); pnt(2)<BR> pnt = ThisDrawing.GetVariable("UCSXDIR")<BR> Debug.Print pnt(0); pnt(1); pnt(2)<BR> pnt = ThisDrawing.GetVariable("UCSYDIR")<BR> Debug.Print pnt(0); pnt(1); pnt(2)<BR> <BR> pnt = ThisDrawing.Utility.TranslateCoordinates(ThisDrawing.GetVariable("UCSXDIR"), acUCS, acWorld, 0)</P>
<P> Debug.Print pnt(0); pnt(1); pnt(2)<BR> <BR> pnt = ThisDrawing.Utility.TranslateCoordinates(ThisDrawing.GetVariable("UCSYDIR"), acUCS, acWorld, 0)</P>
<P> Debug.Print pnt(0); pnt(1); pnt(2)<BR> </P>
<P> </P>
<P><BR> MsgBox "The current UCS is " & currUCS.Name, vbInformation, "ActiveUCS Example"</P>
<P> ' Create a UCS and make it current<BR> origin(0) = 0: origin(1) = 0: origin(2) = 0<BR> xAxis(0) = 1: xAxis(1) = 1: xAxis(2) = 0<BR> yAxis(0) = -1: yAxis(1) = 1: yAxis(2) = 0<BR> Set newUCS = ThisDrawing.UserCoordinateSystems.Add(origin, xAxis, yAxis, "TestUCS")<BR> ThisDrawing.ActiveUCS = newUCS<BR> MsgBox "The new UCS is " & newUCS.Name, vbInformation, "ActiveUCS Example"</P>
<P> ' Reset the UCS to its previous setting<BR> ThisDrawing.ActiveUCS = currUCS<BR> MsgBox "The UCS is reset to " & currUCS.Name, vbInformation, "ActiveUCS Example"<BR>End Sub</P>
<P> </P>
<P> </P> <P>这样就好了。呵呵。小心autodesk蒙人。</P>
<P> </P>
<P> If ThisDrawing.GetVariable("UCSNAME") = "" Then<BR> ' Current UCS is not saved so get the data and save it '.GetVariable("UCSORG"),<BR> With ThisDrawing<BR> Set currUCS = .UserCoordinateSystems.Add( _<BR> pnt1, _<BR> .GetVariable("UCSXDIR"), _<BR> .GetVariable("UCSYDIR"), _<BR> "OriginalUCS")<BR> currUCS.origin = .GetVariable("UCSORG")</P>
<P> End With<BR> Else<BR> Set currUCS = ThisDrawing.ActiveUCS 'current UCS is saved<BR> End If<BR></P>
页:
[1]