无窗口时,如何进行后台调用?
Java开发|大少爷|2017-07-26 09:01
-
回答:
使用
-
回答:
-
回答:
例如: 更多的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(); } }