vb.net查看dwg vbnet findwindow
如何用vb.net编程在cad图形中插入dwg图块?
Dim ppr As PromptPointResult = ed.GetPoint("请选择插入点:")
网站建设哪家好,找创新互联公司!专注于网页设计、网站建设、微信开发、微信小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了泗阳免费建站欢迎大家使用!
Dim pt As Point3d = ppr.Value
utility.WriteToEditor(pt.ToString())
Dim pidBlock As New PIDBlock()
'自己定义的图块类,保存图块的路径和名称
pidBlock.Name = "sample"
pidBlock.Path = blockPath "b_sample.dwg"
Using blkDb As New Database(False, True)
'read drawing
blkDb.ReadDwgFile(pidBlock.Path, System.IO.FileShare.Read, True, Nothing)
blkDb.CloseInput(True)
Using docLock As DocumentLock = doc.LockDocument()
'多文档要先这样,否则报至命错误
Using t As Transaction = doc.TransactionManager.StartTransaction()
'insert it as a new block
Dim idBTR As ObjectId = doc.Database.Insert(pidBlock.Name, blkDb, False)
'create a ref to the block
Dim bt As BlockTable = DirectCast(t.GetObject(doc.Database.BlockTableId, OpenMode.ForRead), BlockTable)
Dim btr As BlockTableRecord = DirectCast(t.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)
Using bref As New BlockReference(pt, idBTR)
btr.AppendEntity(bref)
t.AddNewlyCreatedDBObject(bref, True)
End Using
t.Commit()
End Using
End Using
End Using
VB.NET 如何通过按钮打开AUTOCAD的指定文件
Process.Start(“cad主程序的路径”,“要打开文件的目录”)
比如用记事本打开 c:\1.txt
Process.Start("C:\Windows\notepad.exe", "c:\1.txt")
如何用.NET将DWG文件打印为PDF
执行步骤:打开一个dwg文件,用netload加载下面代码所在的.dll文件,再输入命令plottest,就得到输出结果(一个.pdf文件)。
要用到的参考:
AcDbMgd.dll;AcMgd.dll;AutoCAD 2010 Type Library;System.Windows.Forms; AutoCAD/ObjectDBX Common 18.0 Type Library.
VB.NET:
Imports System
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Autodesk.AutoCAD.Runtime.CommandMethod("Plottest") _
Public Sub PlotToPDF()
Dim activeDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim ThisDrawing As AcadDocument = CType(activeDoc.AcadDocument, AcadDocument)
Dim layout As AcadLayout = ThisDrawing.ActiveLayout
Dim MediaName As String = layout.CanonicalMediaName
If MediaName.Equals("") Then
activeDoc.Editor.WriteMessage("There is no media set for the active layout.")
Return
Else
activeDoc.Editor.WriteMessage(("The media for the active layout is: " + MediaName))
End If
Try
Dim oplot As AcadPlotConfiguration = ThisDrawing.PlotConfigurations.Add("PDF", layout.ModelType)
oplot.PaperUnits = AcPlotPaperUnits.acMillimeters
oplot.StyleSheet = "monochrome.ctb"
oplot.PlotWithPlotStyles = True
oplot.ConfigName = "DWG To PDF.pc3"
oplot.UseStandardScale = True
oplot.StandardScale = AcPlotScale.acScaleToFit
oplot.PlotType = AcPlotType.acExtents
oplot.CenterPlot = True
Dim oMediaNames As Object = layout.GetCanonicalMediaNames
Dim mediaNames As ArrayList = New ArrayList(CType(oMediaNames, String()))
For Each sName As String In mediaNames
If sName.Contains(MediaName) Then
oplot.CanonicalMediaName = sName
layout.CopyFrom(oplot)
layout.PlotRotation = AcPlotRotation.ac0degrees
layout.RefreshPlotDeviceInfo()
ThisDrawing.SetVariable("BACKGROUNDPLOT", 0)
ThisDrawing.Plot.QuietErrorMode = True
ThisDrawing.Plot.PlotToFile("c:/temp/d1.pdf", "DWG To PDF.pc3")
oplot.Delete()
oplot = Nothing
Return
End If
Next
Catch es As System.Exception
System.Windows.Forms.MessageBox.Show(es.ToString)
End Try
End Sub
VB.Net读取AutoCAD图纸
如果可以的话请把分给我
以下是cad2007版的,引用autocad 2007 type library 和autocad/objectdbx common 17如果是04或者版本更低的只要引用autocad 2007 type library,代码的话大同小异,思路是一样的
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
On Error Resume Next
Dim acadapp As Autodesk.AutoCAD.Interop.AcadApplication
acadapp = GetObject(vbNullString, "autoCAD.application")
Dim acaddoc As Autodesk.AutoCAD.Interop.AcadDocument
acaddoc = acadapp.ActiveDocument
Dim Ms As Autodesk.AutoCAD.Interop.Common.AcadModelSpace
Ms = acaddoc.ModelSpace
Dim acadObjectI As Autodesk.AutoCAD.Interop.Common.AcadObject
Dim Linei As Autodesk.AutoCAD.Interop.Common.AcadLine
Dim Circlei As Autodesk.AutoCAD.Interop.Common.AcadCircle
Dim Polylinei As Autodesk.AutoCAD.Interop.Common.AcadPolyline
Dim pt As Autodesk.AutoCAD.Interop.Common.AcadPoint
For Each acadObjectI In Ms
Debug.Print(acadObjectI.ObjectName)
Select Case acadObjectI.ObjectName
Case "AcDbLine"
Linei = acadObjectI
Debug.Print("X =" Linei.StartPoint(0).ToString)
Debug.Print("Y =" Linei.StartPoint(1).ToString)
Case ""
Case ""
End Select
Next
End Sub
网页题目:vb.net查看dwg vbnet findwindow
当前网址:http://ybzwz.com/article/doehhdc.html