⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_17037.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:17037 发表者:㊣客家人 发表日期:2002-10-07 20:46:37
<br>主题:VC调用AUTOCAD类型库acad.tlb时,一个三维点变量怎样转换成VARIANT类型?
<br>内容:VC调用AUTOCAD类型库acad.tlb时,一个三维点变量怎样转换成VARIANT类型?<BR><BR>例画圆函数AddCircle(const VARIANT& Center, double Radius)中的Center是怎样被赋值的?<BR>例如:我想让圆心坐标为(1,1,0),应怎样赋值呢?<BR>附代码<BR>&nbsp;&nbsp;&nbsp;&nbsp;IAcadApplication m_autocad;<BR>&nbsp;&nbsp;&nbsp;&nbsp;IAcadDocuments m_acaddocs;<BR>&nbsp;&nbsp;&nbsp;&nbsp;IAcadDocument&nbsp;&nbsp;m_acaddoc;<BR>&nbsp;&nbsp;&nbsp;&nbsp;IAcadModelSpace m_acadmodel;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;m_autocad.CreateDispatch("AutoCAD.Application")<BR>&nbsp;&nbsp;&nbsp;&nbsp;m_autocad.SetVisible(true);<BR>&nbsp;&nbsp;&nbsp;&nbsp;m_acaddocs.AttachDispatch(m_autocad.GetDocuments(),true);<BR>&nbsp;&nbsp;&nbsp;&nbsp;m_acaddoc.AttachDispatch(m_acaddocs.Add(vtMissing),true);<BR>&nbsp;&nbsp;&nbsp;&nbsp;m_acadmodel.AttachDispatch(m_acaddoc.GetModelSpace(),true);<BR>&nbsp;&nbsp;&nbsp;&nbsp;//想画一个园<BR>&nbsp;&nbsp;&nbsp;&nbsp;VARIANT center;<BR>&nbsp;&nbsp;&nbsp;&nbsp;double radiu=100;<BR>&nbsp;&nbsp;&nbsp;&nbsp;//LPDISPATCH IAcadModelSpace::AddCircle(const VARIANT& Center, double Radius)<BR>&nbsp;&nbsp;&nbsp;&nbsp;//Center 应怎样赋值呢?<BR>&nbsp;&nbsp;&nbsp;&nbsp;m_acadmodel.AddCircle(certer,r);
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:㊣剑不如人♀ 回复日期:2002-10-07 20:50:40
<br>内容:我也很想知道耶!<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:黄飚 回复日期:2002-10-08 09:03:14
<br>内容:acad.tlb 你把这个发给我,我看一下,我想他应该是把其(x,y,z)转化成一个以,分开的字符<BR>“x,y,z"(我裁猜的),如果猜对了,给点分,谢谢,如果不对给我发acad.tlb,分还挺多的
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:㊣剑不如人♀ 回复日期:2002-10-08 10:18:39
<br>内容:如你想得分,装一个autocad,acad.tlb在acad目录中<BR>我的程序是要调用autocad的,也只能在autocad中才能试出结果!
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:黄飚 回复日期:2002-10-08 16:13:49
<br>内容:Using Delphi 3 to write AutoCAD R14 Automation Clients<BR><BR>Here's an example which draws a circle using late binding<BR><BR>When using Late binding with the initial release of R14, you must use the VarArrayRef() function to pass a variant array when AutoCAD requires an array of 3 doubles (a 3D coordinate). In R14.01, you do not need to use VarArrayRef(), and you can just pass the variant array instead.<BR><BR>var<BR>&nbsp;&nbsp;Acad, Circle, vPoint, Mspace : OleVariant;<BR>begin<BR><BR>&nbsp;&nbsp;// Create the point array and assign values to it<BR>&nbsp;&nbsp;vPoint := VarArrayCreate([0,2], VT_R8);<BR>&nbsp;&nbsp;vPoint[0] := 2.0; vPoint[1] := 4.0; vPoint[2] := 0.0;<BR><BR>&nbsp;&nbsp;// Get the AutoCAD application object<BR>&nbsp;&nbsp;Acad := GetActiveOleObject('AutoCAD.Application.14');<BR><BR>&nbsp;&nbsp;// Get the ActiveDocument's model space object<BR>&nbsp;&nbsp;Mspace := Acad.ActiveDocument.Modelspace;<BR><BR>&nbsp;&nbsp;// call the AddCircle() method to create the <BR>&nbsp;&nbsp;// circle with a radius of 10 units:<BR><BR>&nbsp;&nbsp;Circle := Mspace.AddCircle(VarArrayRef(vPoint), 10.0);&nbsp;&nbsp;// R14.00 only<BR><BR>&nbsp;&nbsp;Circle := Mspace.AddCircle(Vpoint, 10.0);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// R14.01 only<BR><BR>&nbsp;&nbsp;// Update the circle<BR>&nbsp;&nbsp;Circle.Update;<BR><BR>end;<BR><BR>Using early binding is a bit more complicated. Delphi has a bug that incorrectly declares SafeArray's as OleVariants in the imported type library (and generates a warning for each, but even the warning is incorrect - these parameters must be declared as const PSafearray (a constant pointer to a TSafeArray). So, for the AddCircle() method used in the above example, this would be the correct declaration that must appear in AutoCAD_TLB.pas:<BR><BR>function AddCircle(const center: PSafeArray; radius: Double): IDispatch; safecall;<BR><BR>Assuming you correct the declaration to read like the above, to use Early binding you must pass the safearray pointer. You can use this helper function to convert a variant array to a PSafeArray:<BR><BR>Function SafeArrayRef(V : OleVariant): PSafeArray;<BR>begin<BR>&nbsp;&nbsp;Result := PSafeArray(TVarData(V).VArray);|<BR>end;<BR><BR>Here is the same example from above, only using early binding:<BR><BR>var<BR>&nbsp;&nbsp;Acad, vPoint: OleVariant;<BR>&nbsp;&nbsp;Mspace : IAcadModelSpace;<BR>&nbsp;&nbsp;Circle : IAcadCircle;<BR>begin<BR>&nbsp;&nbsp;vPoint := VarArrayCreate([0,2], VT_R8);<BR>&nbsp;&nbsp;vPoint[0] := 2.0; vPoint[1] := 4.0; vPoint[2] := 0.0;<BR>&nbsp;&nbsp;Acad := GetActiveOleObject('AutoCAD.Application.14');<BR>&nbsp;&nbsp;Mspace := IDispatch(Acad.ActiveDocument.ModelSpace) as IAcadModelspace;<BR>&nbsp;&nbsp;Circle := IDispatch(Mspace.AddCircle(SafeArrayRef(vPoint), 10.0)) as IAcadCircle;<BR>&nbsp;&nbsp;Circle.Update;<BR>end;<BR>有一个delphi的例子
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:黄飚 回复日期:2002-10-08 16:21:40
<br>内容:AutoCAD, Release 14 Java - nowe mo&#380;liwo&#347;ci dla aplikacji<BR><BR>Listing 1. <BR>// import the library packages used so we can refer <BR>// to objects by their short names<BR>//<BR>import acad.*;<BR>import com.ms.com.*;<BR><BR>public class tryAcad<BR>{<BR>public static void main(String args[])<BR>{<BR>//<BR>// define the Application, Active Document and Model Space objects<BR>//<BR>IAcadApplication IApp = (IAcadApplication) new AcadApplication();<BR>IApp.putVisible(true);<BR>IAcadDocument IDoc = (IAcadDocument) IApp.getActiveDocument();<BR>IAcadUtility IUtil = (IAcadUtility) IDoc.getUtility();<BR>IAcadModelSpace IMSpace = (IAcadModelSpace) IDoc.getModelSpace();<BR>//<BR>// OK, here's where we would actually do something [insert code below]<BR>//<BR>}<BR>}<BR> <BR><BR> <BR><BR>Listing 2. <BR><BR>//<BR>// OK, so lets do something<BR>// Define two points and get user defined values<BR>//<BR>Variant opt = new Variant();<BR>opt.VariantClear();<BR>opt.noParam();<BR>Variant vPt1 = new Variant();<BR>Variant vPt2 = new Variant();<BR>vPt1.VariantClear();<BR>vPt2.VariantClear();<BR>int hr = 0;<BR>Variant prompt = new Variant();<BR>//<BR>// use 'try/catch' to get the point and handle exceptions, if thrown<BR>//<BR>try<BR>{<BR>prompt.putString("Enter starting point ===&gt;");<BR>vPt1 = IUtil.GetPoint(opt, prompt);<BR>}<BR>catch (ComException e)<BR>{<BR>hr = e.getHResult();<BR>}<BR>if (hr == 0)<BR>{<BR>try<BR>{<BR>prompt.putString("Enter ending point ===&gt;");<BR>vPt2 = IUtil.GetPoint(vPt1, prompt);<BR>}<BR>catch (ComException e)<BR>{<BR>hr = e.getHResult();<BR>}<BR>}<BR>//<BR>// draw a Line, a Circle and an Arc<BR>// and give them some colors<BR>//<BR>IAcadLine ILine;<BR>IAcadCircle ICir;<BR>IAcadArc IArc;<BR>if (hr == 0)<BR>{<BR>ILine = (IAcadLine) IMSpace.AddLine(vPt1, vPt2);<BR>ILine.putColor(2);<BR>ICir = (IAcadCircle) IMSpace.AddCircle(vPt1, 2.5);<BR>ICir.putColor(3);<BR>IArc = (IAcadArc) IMSpace.AddArc(vPt2, 2.5, 0.707, 1.414);<BR>IArc.putColor(4);<BR>}<BR>// All done<BR> <BR><BR>T&#322;umaczy&#322;: Wojtek Szypu&#322;a<BR><BR><BR><BR>给一个Java的例子
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:㊣剑不如人♀ 回复日期:2002-10-08 17:26:36
<br>内容:呵呵,C++BUILDER的程序我也有,和DELPHI的差不多<BR>可是VC的我试了半天也不行,可能我对safearray和variant概念还没理解透!
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:㊣剑不如人♀ 回复日期:2002-10-08 18:37:23
<br>内容:HRESULT getDblArrayFromVariant(double pt[3], const VARIANT* pVal)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (!(pVal-&gt;vt & VT_ARRAY && pVal-&gt;vt & VT_R8))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return E_INVALIDARG;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;SAFEARRAY* sPt = pVal-&gt;parray;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;if (SafeArrayGetDim(sPt) != 1)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return E_INVALIDARG;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;long lLbound;<BR>&nbsp;&nbsp;&nbsp;&nbsp;long lUbound;<BR>&nbsp;&nbsp;&nbsp;&nbsp;SafeArrayGetLBound(sPt, 1, &lLbound);<BR>&nbsp;&nbsp;&nbsp;&nbsp;SafeArrayGetUBound(sPt, 1, &lUbound);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;if ((lUbound - lLbound + 1) != 3)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return E_INVALIDARG;<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;HRESULT hr;<BR>&nbsp;&nbsp;&nbsp;&nbsp;for (long i = 0; i &lt; 3; i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ((hr = SafeArrayGetElement(sPt, &i, &pt[i]))!=S_OK)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return hr;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;return S_OK;<BR>}<BR>//<BR>//<BR>//<BR>HRESULT getVariantFromDblArray(VARIANT* pVal, const double pt[3])<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;pVal-&gt;vt = VT_ARRAY | VT_R8;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;SAFEARRAYBOUND rgsaBound;<BR>&nbsp;&nbsp;&nbsp;&nbsp;rgsaBound.lLbound = 0L;<BR>&nbsp;&nbsp;&nbsp;&nbsp;rgsaBound.cElements = 3;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;pVal-&gt;parray = SafeArrayCreate(VT_R8, 1, &rgsaBound);<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (! pVal-&gt;parray)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return E_OUTOFMEMORY;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;HRESULT hr;<BR>&nbsp;&nbsp;&nbsp;&nbsp;for (long i = 0; i &lt; 3; i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ((hr = SafeArrayPutElement(pVal-&gt;parray, &i,<BR>(void*)&pt[i]))!=S_OK)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return hr;<BR>&nbsp;&nbsp;&nbsp;&nbsp;return S_OK;<BR>}<BR>这试过了,这个答案是对的,拿分来!
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -