.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Inserting MText into .dwg
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hello everyone!
I'm trying to make a small program in vb.net that creates are laser drawing. So far I was able to create the drawing from a part in inventor. The only left to do is to add the Part Number + description into this drawing. I'm really struggling on this one. I'm currently able to open the drawing and that's all. I've tried many things from examples I found on forums but it's not working. This is a sample of what I have regarding autocad in my program:
Imports Inventor
Imports System.IO
Imports AutoCAD
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.EditorInput
Private Sub OpenDrawing()
Dim oACAD As New Object
Dim oMtext As AcadMText
oACAD = CreateObject("AutoCAD.Application")
oACAD.visible = True
oACAD.Documents.Open(fileNameAndPath, False)
End Sub
I need to find a way to add Mtext but I don't find anything that I'm able to use in my program. If any of you know a good reference, or have a sample of code I would really appreciate it.
Thanks
Solved! Go to Solution.
Re: Inserting MText into .dwg
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
as you are working from an external EXE /APP (otherwise you would not have to create the AutoCAD-object and so start the application) you only can use COM/ActiveX for communication to the AcadApplication-instance.
And as long as you use VB.NET and COM your best help might be to look to the VBA-internal help as it's quite similar (same object model). So install the VBA-Enabler (be careful, some guys have measured timing conflicts just because it is installed) and look to this help.
In case of MTEXT you'll find that:
Sub Example_AddMtext()
' This example creates an MText object in model space.
Dim MTextObj As AcadMText
Dim corner(0 To 2) As Double
Dim width As Double
Dim text As String
corner(0) = 0#: corner(1) = 10#: corner(2) = 0#
width = 10
text = "This is the text String for the mtext Object"
' Creates the mtext Object
Set MTextObj = ThisDrawing.ModelSpace.AddMText(corner, width, text)
ZoomAll
End Sub
HTH, - alfred -
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Re: Inserting MText into .dwg
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi, Alfred!
No need to install VBA Enabler in order to read AutoCAD ActiveX Documentation. It can be downloaded from http://images.autodesk.com/adsk/files/autocad_2013
Re: Inserting MText into .dwg
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi Alexander,
Much appreciated!
Where do you get that info's from?
Have you got a list of files where to download what from Autodesk? I would like to have the link to the source-code!
- alfred -
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Re: Inserting MText into .dwg
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
alfred.neswadba wrote:
... Where do you get that info's from? ...
alfred.neswadba wrote:
...Have you got a list of files where to download what from Autodesk? I would like to have the link to the source-code!
Oh! I also want a list of such files. ![]()
Re: Inserting MText into .dwg
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
here is the code I use in my vb.net program by the way:
Dim oACAD As New Object
Dim oMtext As AutoCAD.AcadMText
Dim corner(0 To 2) As Double
Dim width As Double = 10
Dim Text As String
Dim XPosition As Double = (-width / 2) + (PartLength / 2)
Dim YPosition As Double = -0.25
corner(0) = XPosition# : corner(1) = YPosition# : corner(2) = 0.0#
Text = "{\fTahoma|b0|i0|c0|p34;\L\C3DWG #" & txtNomLaser.Text & "\l\P\C3MATL: " & DescriptionPiece & "\P\C3QTY:____}"
oACAD = CreateObject("AutoCAD.Application")
oACAD.visible = False
lblStatus.Text = "Ouverture d'Autocad en cours..."
oACAD.Documents.Open(fileNameAndPath, False)
Retry = 0
Dim oDoc As AutoCAD.AcadDocument
oDoc = oACAD.ActiveDocument
lblStatus.Text = "Création des layers en cours..."
Dim LayerText As AutoCAD.AcadLayer = oDoc.Layers.Add("Text")
lblStatus.Text = "Ajout du texte dans le DWG en cours..."
oMtext = oDoc.ModelSpace.AddMText(corner, width, Text)
oMtext.AttachmentPoint = AcAttachmentPoint.acAttachmentPointTopCenter
oMtext.Layer = LayerText.Name.ToString
lblStatus.Text = "Sauvegarde du fichier"
oDoc.Save()
lblStatus.Text = "Fermeture d'Autocad"
oACAD.Quit()
oACAD = Nothing
Thank you very much for your help!



