PD12的自动化武器
Author:zfive5(dong)
Email :zfive5@yahoo.com.cn
引子
前些日子,在用pd12画对象模型的时候,由于自己没有仔细看清规范(看来自己视力真的不太好),导致自己的敲入的属性编码,全都命名为Pascal方式了,一个个点击开改吗?(20几个类,200多个属性呀,估计起码也要30分钟) 咋办? 受一位老同事的影响和教育,打算看看有什么懒惰的方法来达成目标,值得庆幸的是PD12支持自动化(就是IDispatch), 当然还有另一种思路没有实践,估计也没有问题,xml分析.
方法
C#例子:
PdCommon.ApplicationClass a = new PdCommon.ApplicationClass();
PdOOM.BaseModel ExistingModel = (PdOOM.BaseModel)a.OpenModel("D://1.oom", PdCommon.OpenModelFlags.omf_DontOpenView|PdCommon.OpenModelFlags.omf_Hidden);
foreach(PdOOM.Package p<chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="True" sourcevalue="1" unitname="in">1 <span style="color: blue;">in</span></chmetcnv> ExistingModel.Packages)
{
if(p1.Code == "haha")
{
try
{
foreach (PdOOM.Class c<chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="True" sourcevalue="1" unitname="in">1 <span style="color: blue;">in</span></chmetcnv> p4.Classes)
{
if (c1.IsShortcut() == false)
{
foreach (PdOOM.Attribute a<chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="True" sourcevalue="1" unitname="in">1 <span style="color: blue;">in</span></chmetcnv> c1.AllAttributes)
{
string sc="";
If (a1.Code.Length > 1)
sc = a1.Code.Substring(0, 1).ToLower() + a1.Code.Substring(1);
else
sc = a1.Code.ToLower();
a1.Code=sc;
}
}
}
goto ZFIVE5_1;
}
}catch(Exception e2)
{
}
}
}
ZFIVE5_1:
ExistingModel.Close(true);
ExistingModel = null;
这个例子调试编写大约花了1个多小时,比我直接修改可能多花点时间,但作为回报熟悉学会了一种新东西的使用,将来其它类似问题也能够作到通用.
如果有需要和可能的话 ,以后自己编写设计大型程序时 ,一定会考虑 script(自动化 ).当然 xml是更开放的另一种选择 .