.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Inserting MText into .dwg

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
doum90
1040 Views, 5 Replies

Inserting MText into .dwg

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

 

 

5 REPLIES 5
Message 2 of 6
Alfred.NESWADBA
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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 6

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

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 4 of 6

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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 5 of 6


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. Smiley Happy

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 6 of 6
doum90
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!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost