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

Mtext problem

11 REPLIES 11
Reply
Message 1 of 12
gilseorin
686 Views, 11 Replies

Mtext problem

Hi,all.
Some help?
The problem is the part 'Case MTEXT' of the following code.
With what should I replace MTEXT?

Dim Values() As TypedValue =
{New typedvalue(dxfCode.Start, "TEXT,MTEXT")}
Dim prFilter As SelectionFilter = New SelectionFilter(Values) Dim res As PromptSelectionResult = ed.SelectAll(prFilter)

Select case id.gettype.name
case Text
...
case Mtext
....
End Select
11 REPLIES 11
Message 2 of 12
Anonymous
in reply to: gilseorin

> Select case id.gettype.name

returns "ObjectId" if I'm not mistaken, assuming
that 'id' is an ObjectId.

You have to open the entity to determine what
type it is.

Do you know how to open the entity?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5493343@discussion.autodesk.com...
Hi,all.
Some help?
The problem is the part 'Case MTEXT' of the following code.
With what should I replace MTEXT?

Dim Values() As TypedValue =
{New typedvalue(dxfCode.Start, "TEXT,MTEXT")}
Dim prFilter As SelectionFilter = New SelectionFilter(Values) Dim res As PromptSelectionResult = ed.SelectAll(prFilter)

Select case id.gettype.name
case Text
...
case Mtext
....
End Select
Message 3 of 12
gilseorin
in reply to: gilseorin

Thanks for your concern,Tony.
Of course, I know how to.

I attached file working in the each subroutine.
I wish to merge this two subroutines to unique one.
Message 4 of 12
gilseorin
in reply to: gilseorin

Sorry, Here it is.
Message 5 of 12
Anonymous
in reply to: gilseorin

Cconsider spending more time on language and
framework theory and concepts, and learning to
use the language correctly.

IOW, you're using constructs like 'Try/Finally'
and 'Using', without really understanding exactly
what they are or how they work.

Your mixing the use of 'Using' with Try/Finally to
manage transactions, and also not knowing how to
deal with different types of objects, makes it clear
that you're still missing some basic key concepts
that you need, before you can write working code
that you can be reasonably confident will not blow
up when you try to use it.

Here is a sample sub that shows the correct way to
deal with transactions (call Commit() when you're
done, or let the transaction abort if your code fails
before that) and how to test the type of an object,
and then cast to a more specific type.

To get any type of valid candidate entity, you assign
first to the more generic 'Entity' type, and then test
the object's actual type using TypeOf to see if it is
DBText or MTEXT. Once you know which type it is,
you can then cast the object to a variable of that
type (DBText or MText in this case).

As far as combining the two subs you have, I'm
not going to do that, but this should give you an
idea of how to do it yourself.

Private Sub Example()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
Using trans As Transaction = db.TransactionManager.StartTransaction()
Dim Values() As TypedValue = {New TypedValue(DxfCode.Start, "TEXT")}
Dim prFilter As SelectionFilter = New SelectionFilter(Values)
Dim res As PromptSelectionResult = ed.SelectAll(prFilter)
If res.Status = PromptStatus.Error Then Return
Dim SS As SelectionSet = res.Value
Dim idarray As ObjectId() = SS.GetObjectIds()
For i As Integer = 0 To idarray.Length - 1
Dim id As ObjectId = res.Value.Item(i).ObjectId

' all objects encountered here must derive from 'Entity',
' so that is the type you cast to first:

Dim ent1 As Entity = DirectCast(trans.GetObject(id, OpenMode.ForWrite), Entity)

' Next see if the entity's actual type is DBText or MText,
' branch accordingly and cast to a variable of the actual
' type, and then work with the object:

If TypeOf ent1 Is DBText Then
Dim dbtext As DBText = DirectCast(ent1, DBText)
Console.Write("This is a TEXT object")
' code to handle TEXT here
ElseIf TypeOf ent1 Is MText Then
Dim mtext as MText = DirectCast(ent1, MText)
Console.Write("This is an MTEXT object")
' code to handle MTEXT here
End If
Next
' ------------------------------------------------------
' Don't put Commit() in a 'Finally' because you don't
' want to commit the transaction if something
' goes wrong above, and the flow of execution
' transfers out of the Using block prematurely.
' ------------------------------------------------------
trans.Commit()

' The Using construct automatically calls Dispose()
' on the Transaction object here, so you do not need
' to do that manually.

End Using
End Sub


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5494053@discussion.autodesk.com...
Thanks for your concern,Tony.
Of course, I know how to.

I attached file working in the each subroutine.
I wish to merge this two subroutines to unique one.
Message 6 of 12
gilseorin
in reply to: gilseorin

Thank you so much,Tony.
Your advice encouraged me to program more prudently.
I appreciate your kind one deeply.

For another person, I attached final code.
Message 7 of 12
gilseorin
in reply to: gilseorin

My mistake!
In my attached file, I should insert 'Using ~ End Using'.
Of course, 'trans.dispose()' is not.
Message 8 of 12
Anonymous
in reply to: gilseorin

Ugh, here is my first baby steps in VB.NET...
I was trying to use your code but
without of luck
I have Visual Studio .NET 2003 and A2005
on my machine
I created project with form and added your
code into form class
This is waht I have a got so far
See attached picture
What I did wrong?
Thanks in advance

Fatty

~'J'~
Message 9 of 12
gilseorin
in reply to: gilseorin

Ooops, you should basically know the grammar and structure
of the .net.
In this way, there's only endless question.

Inherits System.Windows.Forms.Form //Ok

imports Autodesk.AutoCad.interop // Ooops
imports Autodesk.AutoCad.interop.common //Oh,no.

imports Autodesk.AutoCad.EditorInput //You missed it.

You should learn more from '.net trainning lab' provided
by Autodesk.
And then ask what.
Message 10 of 12
Anonymous
in reply to: gilseorin

I agree, I no so smart as you are,
but where is my EditorInput
As I said before I have VS .NET 2003

See picture please
Message 11 of 12
gilseorin
in reply to: gilseorin

Maybe, you have AutoCad 2005.
I don't like 2005 'cause it has many limitation of realize what
I wish to.

Perhaps,it is difficult to get any advice from other person.
If you should use only Acad 2005, I suggest you get Objectarx SDK and install, then you can see there samples directory.
In the subdirectory, you can also see dotnet directory.

At this time, that's the only method to learn to make code working in Acad 2005.
Message 12 of 12
Anonymous
in reply to: gilseorin

Thank you thank you thank you
You gave me a good idea
Regards,

~'J'~

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