夏威夷群岛
我必须打开目录中的所有dwg,修改一些块属性(如BOM..图纸编号..)然后做一个saveas。
首先,我为已经打开的dwg制作代码,修改它并另存为(带有
mydwg。关闭并保存(ligneF))
所有的工作都打招呼了,很快我就把它放在一个循环中打开了所有的dwg。保存为文件时autocad崩溃。
你能帮助我吗。我试着用readdwgfile选择
应用DocumentManager。打开我在两方面都有相同的错误。
ps 1,如果我只运行open和saveas行,我也会出现同样的错误。
谢谢你的帮助
这是我的密码
[size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] fichiersTrouv = Directory.GetFiles(T_CIBLE.Text, [/size][size=2][color=#a31515][size=2][color=#a31515]"*.dwg"[/color][/size][/color][/size][size=2], SearchOption.AllDirectories)[/size][size=2][color=#0000ff][size=2][color=#0000ff]For[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Each[/color][/size][/color][/size][size=2] ligneF [/size][size=2][color=#0000ff][size=2][color=#0000ff]In[/color][/size][/color][/size][size=2] fichiersTrouv [/size][size=2][color=#008000][size=2][color=#008000]' the list of file is correct[/color][/size][/color][/size][size=2][color=#008000][size=2][color=#008000]'Application.DocumentManager.Open option[/color][/size][/color][/size][size=2][color=#008000][size=2][color=#008000]'Dim mydwg As Document = Application.DocumentManager.Open(ligneF)[/color][/size][/color][/size][size=2][color=#008000][size=2][color=#008000]' Dim myDWG As Document = Application.DocumentManager.MdiActiveDocument[/color][/size][/color][/size][size=2][color=#008000][size=2][color=#008000]' myDB = myDWG.Database[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myDB [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]New[/color][/size][/color][/size][size=2] Database([/size][size=2][color=#0000ff][size=2][color=#0000ff]False[/color][/size][/color][/size][size=2], [/size][size=2][color=#0000ff][size=2][color=#0000ff]True[/color][/size][/color][/size][size=2])[/size][size=2]myDB.ReadDwgFile(ligneF, IO.FileShare.ReadWrite, [/size][size=2][color=#0000ff][size=2][color=#0000ff]True[/color][/size][/color][/size][size=2], [/size][size=2][color=#a31515][size=2][color=#a31515]""[/color][/size][/color][/size][size=2])[/size][size=2][color=#008000][size=2][color=#008000]' this section have no error, it work alone[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Using[/color][/size][/color][/size][size=2] mytrans [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] Transaction = myDB.TransactionManager.StartTransaction[/size][size=2][color=#0000ff][size=2][color=#0000ff]For[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Each[/color][/size][/color][/size][size=2] myBlockName [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]String[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]In[/color][/size][/color][/size][size=2] GetTopLevelBlocks(myDB)[/size][size=2][color=#0000ff][size=2][color=#0000ff]For[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Each[/color][/size][/color][/size][size=2] BRefID [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] ObjectId [/size][size=2][color=#0000ff][size=2][color=#0000ff]In[/color][/size][/color][/size][size=2] GetBRefIDs(myDB, myBlockName)[/size][size=2][color=#0000ff][size=2][color=#0000ff]If[/color][/size][/color][/size][size=2] myBlockName = [/size][size=2][color=#a31515][size=2][color=#a31515]"DANCART"[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Then[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] MYATTVALS [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]New[/color][/size][/color][/size][size=2] Dictionary([/size][size=2][color=#0000ff][size=2][color=#0000ff]Of[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]String[/color][/size][/color][/size][size=2], [/size][size=2][color=#0000ff][size=2][color=#0000ff]String[/color][/size][/color][/size][size=2])[/size][size=2]MYATTVALS.Add([/size][size=2][color=#a31515][size=2][color=#a31515]"PROJET"[/color][/size][/color][/size][size=2], [/size][size=2][color=#a31515][size=2][color=#a31515]"A"[/color][/size][/color][/size][size=2])[/size][size=2]MYATTVALS.Add([/size][size=2][color=#a31515][size=2][color=#a31515]"CLIENT1"[/color][/size][/color][/size][size=2], [/size][size=2][color=#a31515][size=2][color=#a31515]"B"[/color][/size][/color][/size][size=2])[/size][size=2]MYATTVALS.Add([/size][size=2][color=#a31515][size=2][color=#a31515]"CLIENT2"[/color][/size][/color][/size][size=2], [/size][size=2][color=#a31515][size=2][color=#a31515]"C"[/color][/size][/color][/size][size=2])[/size][size=2]MYATTVALS.Add([/size][size=2][color=#a31515][size=2][color=#a31515]"DESSINATEUR"[/color][/size][/color][/size][size=2], [/size][size=2][color=#a31515][size=2][color=#a31515]"D"[/color][/size][/color][/size][size=2])[/size][size=2]MYATTVALS.Add([/size][size=2][color=#a31515][size=2][color=#a31515]"DATE"[/color][/size][/color][/size][size=2], [/size][size=2][color=#a31515][size=2][color=#a31515]"E"[/color][/size][/color][/size][size=2])[/size][size=2]MYATTVALS.Add([/size][size=2][color=#a31515][size=2][color=#a31515]"DESSIN"[/color][/size][/color][/size][size=2], [/size][size=2][color=#a31515][size=2][color=#a31515]"F"[/color][/size][/color][/size][size=2])[/size][size=2][color=#0000ff][size=2][color=#0000ff]Using[/color][/size][/color][/size][size=2] myTrans2 [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] Transaction = BRefID.Database.TransactionManager.StartTransaction[/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myBRef [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] BlockReference = BRefID.GetObject(OpenMode.ForRead)[/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myAttCollection [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] AttributeCollection = myBRef.AttributeCollection[/size][size=2][color=#0000ff][size=2][color=#0000ff]For[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Each[/color][/size][/color][/size][size=2] myAttRefID [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] ObjectId [/size][size=2][color=#0000ff][size=2][color=#0000ff]In[/color][/size][/color][/size][size=2] myAttCollection[/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myAttRef [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] AttributeReference = myAttRefID.GetObject(OpenMode.ForWrite)[/size][size=2][color=#0000ff][size=2][color=#0000ff]If[/color][/size][/color][/size][size=2] MYATTVALS.ContainsKey(myAttRef.Tag) [/size][size=2][color=#0000ff][size=2][color=#0000ff]Then[/color][/size][/color][/size][size=2]myAttRef.TextString = MYATTVALS(myAttRef.Tag)[/size][size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]If[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Next[/color][/size][/color][/size][size=2]myTrans2.Commit()[/size][size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Using[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]If[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Next[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Next[/color][/size][/color][/size][size=2]mytrans.Commit()[/size][size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Using[/color][/size][/color][/size][size=2][color=#0000ff][/color][/size][size=2]myDB.SaveAs(ligneF & [/size][size=2][color=#a31515][size=2][color=#a31515]"1.dwg"[/color][/size][/color][/size][size=2], DwgVersion.AC1004) [/size][size=2][color=#008000][size=2][color=#008000]' crash on this line[/color][/size][/color][/size][size=2]myDB.Dispose()[/size][size=2][color=#008000][size=2][color=#008000]' mydwg.CloseAndSave(ligneF) 'Application.DocumentManager.Open option crash [/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Next[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Sub[/color][/size][/color][/size]