yuangw1234 发表于 2006-4-4 23:27:00

请指教VBA中如何提取对象属性

<P>高手请指教:</P>
<P>请问一下哪位高手,在vba中怎样得到所选择物体的圆心(假如所选择的物体是圆),我有如下一个程式,就是改色(这个简单),</P>
<P>Public Sub pi()<BR>Dim ssetobj As AcadSelectionSet<BR>Dim icount As Integer<BR>icount = ThisDrawing.SelectionSets.Count<BR>While (icount &gt; 0)<BR>&nbsp;&nbsp;&nbsp; If ThisDrawing.SelectionSets.Item(icount - 1).Name = "yuan" Then<BR>&nbsp;&nbsp;&nbsp; ThisDrawing.SelectionSets.Item(icount - 1).Delete<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; icount = icount - 1<BR>&nbsp;&nbsp;&nbsp; Wend<BR>&nbsp;&nbsp;&nbsp; Set ssetobj = ThisDrawing.SelectionSets.Add("yuan")<BR>&nbsp;&nbsp;&nbsp; ThisDrawing.Utility.Prompt "please select object"<BR>&nbsp;&nbsp;&nbsp; ssetobj.SelectOnScreen<BR>&nbsp; Dim i As Integer<BR>&nbsp; Dim selobj As AcadEntity<BR><FONT color=#4db376><BR></FONT>&nbsp; For i = 0 To ssetobj.Count - 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set selobj = ssetobj.Item(i)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If selobj.ObjectName = "AcDbCircle" Then<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; selobj.color = acBlue<BR>&nbsp;&nbsp;&nbsp;&nbsp; MsgBox nam</P>
<P>End If<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>End Sub</P>
<P><FONT color=#ff6600>现在请问一下高手,我怎么样才可以得到这样圆心的坐标</FONT></P>
<P><FONT color=#f70909>因为不可以象这样写</FONT></P>
<P><FONT color=#f70909>dim centerpt(0 to 2)&nbsp;as double</FONT></P>
<P><FONT color=#f70909>centerpt=selobj.center&nbsp; (因为这里的selobj没有center中心这样属性)</FONT></P>
<P><FONT color=#f70909>请高手指教,用怎样的方法才可以得到所选物体的圆心再赋给一变量</FONT></P>
<P><FONT color=#f70909>因为我想用这个圆心来画别的东本,而visual Lisp 中则有一个这样的</FONT></P>
<P><FONT color=#f70909>函数 Val-get-center,现在请教高手在vba里可以用什么方法</FONT></P>
<P><FONT color=#f70909>多谢!<BR></P></FONT>

雪山飞狐_lzh 发表于 2006-4-5 19:15:00

<P><FONT color=#f70909>dim centerpt</FONT></P>
<P><FONT color=#f70909>centerpt=selobj.center&nbsp; </FONT></P>

xinghesnak 发表于 2006-4-6 15:35:00

<P><A name=6454><FONT color=#000066><B>yuangw1234</B></FONT></A> ,你说的不对,不是没有这样的属性,而是你提这个属性的方法不对,版主的方法最简单,这样也可以</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim centerpt(2) As Double<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim value<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; j = 0<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Each value In selobj.Center<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; centerpt(j) = value<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; j = j + 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next</P>

yuangw1234 发表于 2006-4-6 22:28:00

多谢<A name=6685><FONT color=#000066><B>xinghesnak</B></FONT></A>

yuangw1234 发表于 2006-4-9 23:00:00

请问假如选择的是一个块(由圆组成),这种方法还管用吗
页: [1]
查看完整版本: 请指教VBA中如何提取对象属性