.NET

Reply
Contributor
doum90
Posts: 20
Registered: ‎01-05-2012
Message 1 of 6 (385 Views)
Accepted Solution

Inserting MText into .dwg

385 Views, 5 Replies
01-27-2013 07:41 PM

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

 

 

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 -

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!

*Expert Elite*
Alfred.NESWADBA
Posts: 9,420
Registered: ‎06-29-2007
Message 2 of 6 (371 Views)

Re: Inserting MText into .dwg

01-28-2013 01:36 AM in reply to: doum90

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
-------------------------------------------------------------------------
Moderator
Alexander.Rivilis
Posts: 1,449
Registered: ‎04-09-2008
Message 3 of 6 (366 Views)

Re: Inserting MText into .dwg

01-28-2013 01:57 AM in reply to: Alfred.NESWADBA

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_activex_help.zip


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

*Expert Elite*
Alfred.NESWADBA
Posts: 9,420
Registered: ‎06-29-2007
Message 4 of 6 (363 Views)

Re: Inserting MText into .dwg

01-28-2013 02:04 AM in reply to: Alexander.Rivilis

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!animierte smilies lachen grinsen happy freuen smilen witzig froh

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Moderator
Alexander.Rivilis
Posts: 1,449
Registered: ‎04-09-2008
Message 5 of 6 (362 Views)

Re: Inserting MText into .dwg

01-28-2013 02:10 AM in reply to: Alfred.NESWADBA

alfred.neswadba wrote:

... Where do you get that info's from? ...


http://hyperpics.blogs.com/beyond_the_ui/2012/09/updated-autocad-2013-activex-developer-documentatio...

 


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!animierte smilies lachen grinsen happy freuen smilen witzig froh


Oh! I also want a list of such files. :smileyhappy:


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Contributor
doum90
Posts: 20
Registered: ‎01-05-2012
Message 6 of 6 (334 Views)

Re: Inserting MText into .dwg

01-28-2013 04:49 PM in reply to: Alfred.NESWADBA

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!

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!