- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 csharp 于 2014-5-11 08:19 编辑
http://www.theswamp.org/index.php?topic=37409.50;wap2
I'd guess that your translation may be skewey.
Can you post the VB.net code you used for each or post he solution zipped so I can test it here.
huiz:
I thought they did work in C# but unfortunately not in vb. Here are the examples in vb:
--- Code: ---<CommandMethod("InsDXF7")> _
Public Sub InsDXF7()
Dim doc As Document = AcadApp.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim db As Database = doc.Database
Dim tmpDb As New Database(False, True)
tmpDb.DxfIn("K:\ToTest\Squircle.dxf", "K:\ToTest\Squircle.log")
Dim pnt1 As New Point3d(0, 0, 0)
Dim pnt2 As New Point3d(1000, 1000, 0)
Dim scale As Double = 10.0
Dim vector As New Vector3d(0, 0, 0)
Dim transform As Matrix3d = Matrix3d.Scaling(scale, pnt2) * Matrix3d.Displacement(pnt1.GetVectorTo(pnt2))
Dim lastEnt As ObjectId = AcUtils.EntLast()
Dim newColor As Autodesk.AutoCAD.Colors.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, 1)
db.Insert(transform, tmpDb, True)
Using tr As Transaction = doc.TransactionManager.StartTransaction()
' if the db was empty lastent will be null
Try
If lastEnt = ObjectId.Null Then
lastEnt = AcUtils.EntFirst()
idColl.Add(lastEnt)
End If
Dim nextent As ObjectId = AcUtils.EntNext(lastEnt)
While nextent <> ObjectId.Null
idColl.Add(nextent)
nextent = AcUtils.EntNext(nextent)
End While
For Each id As ObjectId In idColl
Dim acEntity As Entity = DirectCast(tr.GetObject(id, OpenMode.ForWrite), Entity)
acEntity.Color = newColor
Next
Catch exx As Autodesk.AutoCAD.Runtime.Exception
ed.WriteMessage(vbLf & exx.ToString())
End Try
tr.Commit()
End Using
End Sub
--- End code ---
--- Code: ---<CommandMethod("InsDXF8")> _
Public Sub InsDXF8()
Dim doc As Document = AcadApp.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim db As Database = doc.Database
Dim tmpDb As New Database(False, True)
tmpDb.DxfIn("K:\ToTest\Squircle.dxf", "K:\ToTest\Squircle.log")
Dim pnt1 As New Point3d(0, 0, 0)
Dim pnt2 As New Point3d(1000, 1000, 0)
Dim scale As Double = 10.0
Dim vector As New Vector3d(0, 0, 0)
Dim transform As Matrix3d = Matrix3d.Scaling(scale, pnt2) * Matrix3d.Displacement(pnt1.GetVectorTo(pnt2))
Dim idColl As New ObjectIdCollection()
Dim lastEnt As ObjectId = AcUtils.EntLast()
Dim acEntity As Entity
Dim newColor As Autodesk.AutoCAD.Colors.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, 1)
db.Insert(transform, tmpDb, True)
Using tr As Transaction = doc.TransactionManager.StartTransaction()
' if the db was empty lastent will be null
Try
If lastEnt = ObjectId.Null Then
lastEnt = AcUtils.EntFirst()
acEntity = DirectCast(tr.GetObject(lastEnt, OpenMode.ForWrite), Entity)
acEntity.Color = newColor
End If
Dim nextent As ObjectId = AcUtils.EntNext(lastEnt)
While nextent <> ObjectId.Null
acEntity = DirectCast(tr.GetObject(nextent, OpenMode.ForWrite), Entity)
acEntity.Color = newColor
nextent = AcUtils.EntNext(nextent)
End While
Catch exx As Autodesk.AutoCAD.Runtime.Exception
ed.WriteMessage(vbLf & exx.ToString())
End Try
tr.Commit()
End Using
End Sub
--- End code ---
--- Code: ---<CommandMethod("InsDXF9")> _
Public Sub InsDXF9()
Dim doc As Document = AcadApp.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim db As Database = doc.Database
Dim tmpDb As New Database(False, True)
tmpDb.DxfIn("K:\ToTest\Squircle.dxf", "K:\ToTest\Squircle.log")
Dim pnt1 As New Point3d(0, 0, 0)
Dim pnt2 As New Point3d(1000, 1000, 0)
Dim scale As Double = 10.0
Dim vector As New Vector3d(0, 0, 0)
Dim transform As Matrix3d = Matrix3d.Scaling(scale, pnt2) * Matrix3d.Displacement(pnt1.GetVectorTo(pnt2))
Dim idColl As New ObjectIdCollection()
Dim acEntity As Entity
Dim newColor As Autodesk.AutoCAD.Colors.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, 1)
Using tr As Transaction = tmpDb.TransactionManager.StartTransaction()
Try
Dim tmpDbBlockTable As BlockTable = DirectCast(tr.GetObject(tmpDb.BlockTableId, OpenMode.ForRead), BlockTable)
Dim tmpDbModelSpace As BlockTableRecord = DirectCast(tr.GetObject(tmpDbBlockTable(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)
For Each id As ObjectId In tmpDbModelSpace
acEntity = DirectCast(tr.GetObject(id, OpenMode.ForWrite), Entity)
acEntity.Color = newColor
Next
tr.Commit()
Catch exx As Autodesk.AutoCAD.Runtime.Exception
ed.WriteMessage(vbLf & exx.ToString())
End Try
End Using
db.Insert(transform, tmpDb, True)
End Sub
--- End code ---
Kerry:
Give these a run ...
(Code solution .ZIP attached)
--- Code: ---
Option Explicit On
Option Strict On
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Colors
Imports Utils = Autodesk.AutoCAD.Internal.Utils
<Assembly: CommandClass(GetType(InsertDXF.MyCommands))>
Namespace InsertDXF
Public Class MyCommands
'' < snip >
End Class
End Namespace
--- End code ---
--- Code: ---
<CommandMethod("InsDXF7")> _
Public Sub InsDXF7()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim db As Database = doc.Database
Dim tmpDb As New Database(False, True)
tmpDb.DxfIn("K:\\ToTest\\Squircle.dxf", "K:\ToTest\\Squircle.log")
Dim pnt1 As New Point3d(0, 0, 0)
Dim pnt2 As New Point3d(1000, 1000, 0)
Dim scale As Double = 10
Dim vector As New Vector3d(0, 0, 0)
Dim transform As Matrix3d = (Matrix3d.Scaling(scale, pnt2) _
* Matrix3d.Displacement(pnt1.GetVectorTo(pnt2)))
Dim idColl As New ObjectIdCollection
Dim lastEnt As ObjectId = Utils.EntLast
Dim newColor As Color = Color.FromColorIndex(ColorMethod.ByAci, 1)
db.Insert(transform, tmpDb, True)
Using tr As Transaction = doc.TransactionManager.StartTransaction
Try
If (lastEnt = ObjectId.Null) Then
lastEnt = Utils.EntFirst
idColl.Add(lastEnt)
End If
Dim nextent As ObjectId = Utils.EntNext(lastEnt)
Do While (nextent <> ObjectId.Null)
idColl.Add(nextent)
nextent = Utils.EntNext(nextent)
Loop
Dim id As ObjectId
For Each id In idColl
Dim acEntity As Entity = DirectCast(tr.GetObject( _
id, OpenMode.ForWrite), Entity)
acEntity.Color = newColor
Next
Catch exx As Autodesk.AutoCAD.Runtime.Exception
ed.WriteMessage((ChrW(10) & exx.ToString))
End Try
tr.Commit()
End Using
End Sub
--- End code ---
--- Code: ---
<CommandMethod("InsDXF8")> _
Public Sub InsDXF8()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim db As Database = doc.Database
Dim tmpDb As New Database(False, True)
tmpDb.DxfIn("K:\\ToTest\\Squircle.dxf", "K:\\ToTest\\Squircle.log")
Dim pnt1 As New Point3d(0, 0, 0)
Dim pnt2 As New Point3d(1000, 1000, 0)
Dim scale As Double = 10
Dim vector As New Vector3d(0, 0, 0)
Dim transform As Matrix3d = (Matrix3d.Scaling(scale, pnt2) _
* Matrix3d.Displacement(pnt1.GetVectorTo(pnt2)))
Dim idColl As New ObjectIdCollection
Dim lastEnt As ObjectId = Utils.EntLast
Dim newColor As Color = Color.FromColorIndex(ColorMethod.ByAci, 1)
db.Insert(transform, tmpDb, True)
Using tr As Transaction = doc.TransactionManager.StartTransaction
Try
Dim acEntity As Entity
If (lastEnt = ObjectId.Null) Then
lastEnt = Utils.EntFirst
acEntity = DirectCast(tr.GetObject( _
lastEnt, OpenMode.ForWrite), Entity)
acEntity.Color = newColor
End If
Dim nextent As ObjectId = Utils.EntNext(lastEnt)
Do While (nextent <> ObjectId.Null)
acEntity = DirectCast(tr.GetObject( _
nextent, OpenMode.ForWrite), Entity)
acEntity.Color = newColor
nextent = Utils.EntNext(nextent)
Loop
Catch exx As Autodesk.AutoCAD.Runtime.Exception
ed.WriteMessage((ChrW(10) & exx.ToString))
End Try
tr.Commit()
End Using
End Sub
--- End code ---
--- Code: ---
<CommandMethod("InsDXF9")> _
Public Sub InsDXF9()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim db As Database = doc.Database
Dim tmpDb As New Database(False, True)
tmpDb.DxfIn("K:\\ToTest\\Squircle.dxf", "K:\\ToTest\Squircle.log")
Dim pnt1 As New Point3d(0, 0, 0)
Dim pnt2 As New Point3d(1000, 1000, 0)
Dim scale As Double = 10
Dim vector As New Vector3d(0, 0, 0)
Dim transform As Matrix3d = (Matrix3d.Scaling(scale, pnt2) _
* Matrix3d.Displacement(pnt1.GetVectorTo(pnt2)))
Dim newColor As Color = Color.FromColorIndex(ColorMethod.ByAci, 1)
Dim tr As Transaction = tmpDb.TransactionManager.StartTransaction
Try
Dim tmpDbBlockTable As BlockTable = DirectCast(tr.GetObject( _
tmpDb.BlockTableId, OpenMode.ForRead), BlockTable)
Dim tmpDbModelSpace As BlockTableRecord = DirectCast(tr.GetObject( _
tmpDbBlockTable.Item(BlockTableRecord.ModelSpace), _
OpenMode.ForWrite), BlockTableRecord)
Dim id As ObjectId
For Each id In tmpDbModelSpace
Dim acEntity As Entity = DirectCast(tr.GetObject( _
id, OpenMode.ForWrite), Entity)
acEntity.Color = newColor
Next
tr.Commit()
Catch exx As Autodesk.AutoCAD.Runtime.Exception
ed.WriteMessage((ChrW(10) & exx.ToString))
Finally
If (Not tr Is Nothing) Then
tr.Dispose()
End If
End Try
db.Insert(transform, tmpDb, True)
End Sub
--- End code ---
kaefer:
--- Quote from: Kerry on March 29, 2011, 02:35:49 am ---
--- Code: ---Option Explicit On
Option Strict On
--- End code ---
--- End quote ---
Does the culprit sit right here?
Cheers, Thorsten (missing bargepole, won't do VB)
Kerry:
--- Quote from: kaefer on March 29, 2011, 03:18:43 am ---
--- Quote from: Kerry on March 29, 2011, 02:35:49 am ---
--- Code: ---Option Explicit On
Option Strict On
--- End code ---
--- End quote ---
Does the culprit sit right here?
Cheers, Thorsten (missing bargepole, won't do VB)
--- End quote ---
Don't know Thorsten, but it didn't seen correct to me to code with them off .... but that's probably just me :)
I've decided I need to at least be able to read VB and write a little ... as much as I hate the Dim word :-P
|
|