lewis770227 Posted February 9, 2009 Posted February 9, 2009 I have a problem working with USC, for example I try to change de USC to locate a new point and Add a line using that point and other created before, I show you a fragment of code I wrote for this. the problem is that when I define x0, y0 and z0, note that when I do this it suppoused that USC was changed (newUCS), so x0,y0 and z0 are located by the previous USC. Best regards my friends Note:I know m2,xm If ThisDrawing.GetVariable("UCSNAME") = "" Then With ThisDrawing Set currUCS = .UserCoordinateSystems.Add( _ .GetVariable("UCSORG"), _ .Utility.TranslateCoordinates(.GetVariable("UCSXDIR"), acUCS, acWorld, 0), _ .Utility.TranslateCoordinates(.GetVariable("UCSYDIR"), acUCS, acWorld, 0), _ "OriginalUCS") End With Else Set currUCS = ThisDrawing.ActiveUCS 'current UCS is saved End If If m2 x3 = xm - 1: y3 = -m2 + ym: z3 = 0 ElseIf m2 > 0 Then x3 = xm + 1: y3 = m2 + ym: z3 = 0 End If origin(0) = xm: origin(1) = ym: origin(2) = zm xAxis(0) = x2: xAxis(1) = y2: xAxis(2) = z2 yAxis(0) = x3: yAxis(1) = y3: yAxis(2) = z3 Set newUCS = ThisDrawing.UserCoordinateSystems.Add(origin, xAxis, yAxis, "TestUCS") ThisDrawing.ActiveUCS = newUCS 'Change UCS x0 = 0: y0 = -Dist(0): z0 = 0 startPoint(0) = xm: startPoint(1) = ym: startPoint(2) = zm endPoint(0) = x0: endPoint(1) = y0: endPoint(2) = z0 Set lineObj = ThisDrawing.ModelSpace.AddLine(startPoint, endPoint) ThisDrawing.ActiveUCS = currUCS 'Reset to the previous UCS End Sub Quote
SEANT Posted February 10, 2009 Posted February 10, 2009 The coordinates to build an object in VBA are always interpreted as WCS, regardless of current UCS. With that in mind the routine posted above could be modified to something like: . . . . Dim varUCSMatrix as Variant . . . . ‘may not need to store current UCS If m2 < 0 Then x3 = xm - 1: y3 = -m2 + ym: z3 = 0 ElseIf m2 > 0 Then x3 = xm + 1: y3 = m2 + ym: z3 = 0 End If origin(0) = xm: origin(1) = ym: origin(2) = zm xAxis(0) = x2: xAxis(1) = y2: xAxis(2) = z2 yAxis(0) = x3: yAxis(1) = y3: yAxis(2) = z3 Set newUCS = ThisDrawing.UserCoordinateSystems.Add(origin, xAxis, yAxis, "TestUCS") ‘no need to set newUCS current varUCSMatrix = newUCS.GetUCSMatrix x0 = 0: y0 = -Dist(0): z0 = 0 startPoint(0) = xm: startPoint(1) = ym: startPoint(2) = zm endPoint(0) = x0: endPoint(1) = y0: endPoint(2) = z0 Set lineObj = ThisDrawing.ModelSpace.AddLine(startPoint, endPoint) lineObj.TransformBy varUCSMatrix ‘ThisDrawing.ActiveUCS = currUCS '(possibly not needed) End Sub Quote
lewis770227 Posted February 10, 2009 Author Posted February 10, 2009 Thanks I thought that changing USC and make it current I solved the problem I don´t know about the transformby method. Reading the help I saw that this is applicable to any object in drawing, that is a powerfull tool. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.