用后台调用,无窗口时,需要使用控件的功能,就使用该组件。
[ object, uuid(6165D852-038F-4D36-9554-E58CC1C78CC3), dual, nonextensible, helpstring("IMxDrawService interface"), pointer_default(unique) ]
interface IMxDrawService : IDispatch;
MxDrawService.idl
例如: JAVA后台调用例子.
ActiveXComponent smsg = new ActiveXComponent("MxDrawX.MxDrawService"); // 获取Active对象 Dispatch msg = smsg.getObject(); // 调用组件方法,打开指定dwg文件 msg.call(msg, "open", myFilePath+dirname+"/"+filename); // 参数 jpg保存路径,位图宽度方向的像素,-1取系统默认值:1000 ,位图宽度方向的像素,-1取系统默认值:1000 Object[] params = new Object[] { myFilePath+picName, 600, 860 }; //将打开的dwg图纸,保存为jpg文件. Object[] colorparams = new Object[] { 255, 255, 255 }; msg.call(msg, "SetViewColor", colorparams); msg.call(msg, "WriteJpg", params); //关闭打开的dwg文件 msg.call(msg, "close"); smsg.safeRelease();
例如: VB代码.
Dim sver As MxDrawService Set sver = New MxDrawService sver.Open "c:1.dwg" sver.SetViewColor 255, 255, 255 sver.WriteJpg "c:1.jpg", 1000, 1000 sver.Close
例如: 更多的java调用演示例子.
package com.jo.work.mxdraw.action; import com.jacob.activeX.ActiveXComponent; import com.jacob.com.Dispatch; public class AutoMxDrawComputeService { public static void main(String[] args) throws Exception{ AutoMxDrawComputeService auto=new AutoMxDrawComputeService(); auto.autoDraw(); } /* * 演示如何在java中调用COM组件 */ public void autoDraw() throws Exception{ ActiveXComponent smsg = new ActiveXComponent("MxDrawX.MxDrawService"); // 获取Active对象 Dispatch msg = smsg.getObject(); msg.call(msg, "open", "f://empty.dwg"); // 调用组件方法,打开指定dwg文件 Dispatch databae = msg.call(msg, "GetDatabase").toDispatch(); Dispatch blkRec = databae.call(databae, "CurrentSpace").toDispatch(); //文本 Object[] text = new Object[] {100,100, "444444", 10}; blkRec.call(blkRec,"AddText",text); //线 Object[] line = new Object[] {200,200, 700, 200}; blkRec.call(blkRec,"AddLine",line); //圆 Object[] circle = new Object[] {600,600, 50}; blkRec.call(blkRec,"AddCircle",circle); //插入图块 ActiveXComponent sdatabase = new ActiveXComponent("MxDrawX.MxDrawDatabase"); // 获取Active对象 Dispatch blkDatabase = sdatabase.getObject(); Object[] readdwg = new Object[] {"F://1.dwg",""}; blkDatabase.call(blkDatabase, "ReadDwgFile",readdwg); Object[] toblk1 = new Object[] {blkDatabase,"blk1"}; databae.call(databae, "Insert",toblk1); Object[] toblk2 = new Object[] {600,600,"blk1",1,0}; blkRec.call(blkRec,"InsertBlock",toblk2); ActiveXComponent sss = new ActiveXComponent("MxDrawX.MxDrawSelectionSet"); Dispatch ss = sss.getObject(); ActiveXComponent sfilter = new ActiveXComponent("MxDrawX.MxDrawResbuf"); Dispatch filter = sfilter.getObject(); Object[] selectparamsrs = new Object[] {filter}; ss.call(ss,"AllSelect",selectparamsrs); for (int i = 0; i < ss.get(ss,"Count").toInt(); i++){ Object[] paramsrss = new Object[] {i}; Dispatch ent = ss.call(ss,"Item",paramsrss).toDispatch(); if (ent == null){ continue; } if (ent.get(ent,"ObjectName").toString().equals("McDbBlockReference")){ //ActiveXComponent blockss = new ActiveXComponent("MxDrawX.MxDrawBlockReference"); //Dispatch blockssss = blockss.getObject(); Dispatch blkRecs=ent.get(ent,"BlockTableRecord").toDispatch(); // Dispatch blkRecsssss=blkRecs.get(blkRecs,"GetEntity").toDispatch(); Dispatch iter= blkRecs.call(blkRecs,"NewIterator").toDispatch(); Object[] paramsriter = new Object[] {0}; System.out.println(iter.Get); // for(int k=0;k<iter.VariantInt;k++){ // Object[] paramsrssit = new Object[] {k}; // Dispatch tmpEnt = blkRecs.get(blkRecs,"GetEntity").toDispatch(); // } // System.out.println(iter.VariantInt); // int size=blkRecss.get(blkRecss,"Count").toInt(); // // System.out.println("=size=:"+size); }else if (ent.get(ent,"ObjectName").toString().equals("McDbText")){ String texts=ent.get(ent,"TextString").toString(); System.out.println("查找的结果:"+texts); ent.put(ent,"TextString",texts+"-替换"); System.out.println(ent.get(ent,"TextString")); } } //输出文件 Object[] paramsrs = new Object[] {"F://a3t.dwg"}; msg.call(msg, "SaveDwgFile", paramsrs); smsg.safeRelease(); } }
例如: C#代码.
// 创建一个无控件界面的服务器组件对象 MxDrawService ser = new MxDrawService(); // 打开文件 ser.Open("H:\Drawing2.dwg"); // 得到打开文件的数据库 MxDrawDatabase databse = ser.GetDatabase(); // 打开图块文件 MxDrawDatabase blkDatabase = new MxDrawDatabase(); blkDatabase.ReadDwgFile("H:\tree.dwg",""); // 把图块文件插入到前面打开的文件中,用块的形式插入,块名为myblkname databse.Insert(blkDatabase, "myblkname"); // 得到当前打开文件的绘图空间 MxDrawBlockTableRecord curSpace = databse.CurrentSpace(); // 向绘图空间插入一个块引用 MxDrawBlockReference blkRef = curSpace.InsertBlock(0, 0, "myblkname"); // 打碎这个图块引用 blkRef.Explode(); // 把当前图纸保存到new.dwg ser.SaveDwgFile("H:\new.dwg");