davehuhudave 发表于 2010-8-3 08:33:00

<p>我用的cad2007,net2005</p>

davehuhudave 发表于 2010-8-3 08:36:00

<p>主要代码再贴一下:</p>
<p><font face="Verdana">Dim pg As MyPropertyGrid.CustomClass = PropertyGrid1.SelectedObject<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim ed As Editor = AcadApp.DocumentManager.MdiActiveDocument.Editor<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim db As Database = AcadApp.DocumentManager.MdiActiveDocument.Database<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim lock As DocumentLock = AcadApp.DocumentManager.MdiActiveDocument.LockDocument()<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Using trans As Transaction = db.TransactionManager.StartTransaction()<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim attref As AttributeDefinition = trans.GetObject(selID, OpenMode.ForWrite)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'attref.TextString = pg.Item("属性值").ToString<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim mCustomer As CustomerFilter = pg.Item("属性值")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; attref.TextString = mCustomer.path<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim s As String = pg.Item("显示否").ToString<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If String.Compare(s, "True") = 0 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; attref.Visible = True<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; attref.Visible = False<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim c As Color = pg.Item("颜色")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim cc As Autodesk.AutoCAD.Colors.Color = Autodesk.AutoCAD.Colors.Color.FromColor(c)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; attref.Color = cc<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s = pg.Item("大小").ToString<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; attref.Height = Int(Val(s))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s = pg.Item("旋转角").ToString<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; attref.Rotation = Double.Parse(s)</font></p>
<p><font face="Verdana">&nbsp;&nbsp;&nbsp;&nbsp;''''''''''''''''''''''''''''''''''''''''''''''''上面的属性全部改掉了<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim p As Point = pg.Item("相对位置")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; attref.Position = New Point3d(p.X, p.Y, 0)</font></p>
<p><font face="Verdana">''''''''''''''''''''''''''''''''''''''''''''''''''''''此时跟踪得到也改掉了<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; trans.Commit()</font></p>
<p>''''''''''''''''''''''''''''''''''''''''''''''''''''''''跟踪又改回去了Position的值,而其他属性已经改掉,没有变回去<font face="Verdana"><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ed.Regen()<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Using<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lock.Dispose()</font></p>

davehuhudave 发表于 2010-8-4 09:10:00

??anyone help?

雪山飞狐_lzh 发表于 2010-8-4 10:05:00

<p>用7楼的代码测试下</p>

cobalt 发表于 2010-8-4 13:42:00

<p align="left">原因就是你的属性定义的对齐点没有更新。</p>
<p align="left">加入下面的代码试一试吧。</p>
<p align="left">&nbsp;</p>
<p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If attdef.HorizontalMode &lt;&gt; TextHorizontalMode.TextLeft Then</p>
<p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; attdef.AlignmentPoint = attdef.Position</p>
<p align="left">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If</p>

雪山飞狐_lzh 发表于 2010-8-4 14:58:00

<p><font face="Verdana" color="#61b713"><b>cobalt</b></font>说的没错</p>
<p>如果dbtext、attdef、attref的式样不是左下或调整</p>
<p>Position是无效的</p>

davehuhudave 发表于 2010-8-5 13:12:00

果然好主意,可是新问题出现了,这样我采取了不使用任何对齐方式的方式,结果AttributeDefinition 可以改变任何属性了,但是她的块参照属性<font face="Verdana">AttributeReference</font>却改不了<font face="Verdana">TextString</font>了,现象差不多,只不过变成了<font face="Verdana">TextString</font>属性,以前是可以的

davehuhudave 发表于 2010-8-5 13:16:00

所有属性都不能改,晕

davehuhudave 发表于 2010-8-5 13:39:00

o了,搞错了,

davehuhudave 发表于 2010-8-5 13:41:00

现在发现都能改了,但是文字却不能显示了,实际位置没错,显示状态没错,就是没看到,点击属性也发现名称是有的,就是显示不出来
页: 1 [2]
查看完整版本: 关于块定义AttributeDefinition