Export MTEXT Contents

Export MTEXT Contents

Anonymous
Not applicable
2,233 Views
11 Replies
Message 1 of 12

Export MTEXT Contents

Anonymous
Not applicable

Hello,

 

I am using the Navisworks API to create a plugin that performs certain tasks with mtext objects. However, the MTEXT properties in Navisworks do not contain the Contents property that is in AutoCad. 

 

For example, here is a picture of the model item properties in AutoCad. It shows that the Contents are equal to "1138".

MTEXT Contents AC.PNG

 

Here is the same model item in Navisworks. I've used a plugin that shows all of the properties for a model item so you can see that the contents aren't transferred when the .dwg imports into Navisworks.

 MTEXT Contents NW.PNG

 

Is there something I can from the AutoCad side to make this work? Thanks!

 

0 Likes
Accepted solutions (1)
2,234 Views
11 Replies
Replies (11)
Message 2 of 12

pendean
Community Legend
Community Legend
Nope.
0 Likes
Message 3 of 12

Anonymous
Not applicable

Is it possible to use an AutoCad plugin to copy the contents of each MTEXT item into the hyperlink property field? 

 

I ask because the hyperlink property does transfer to Navisworks.

 

Thanks for the reply!

0 Likes
Message 4 of 12

john.vellek
Alumni
Alumni

Hi austin.rausch9NCU2

 

 

Are you trying to capture all the text from the AutoCAD drawing or just certain pieces? if you are doing the latter, do blocks and attributes work better to get it into Navisworks?

 


John Vellek


Join the Autodesk Customer Council - Interact with developers, provide feedback on current and future software releases, and beta test the latest software!

Autodesk Knowledge Network | Autodesk Account | Product Feedback
0 Likes
Message 5 of 12

john.vellek
Alumni
Alumni

Good morning austin.rausch9NCU2,

 


I am checking back to see if you had resolved your problem. Please add a post with your results so other Forum users can benefit.



John Vellek


Join the Autodesk Customer Council - Interact with developers, provide feedback on current and future software releases, and beta test the latest software!

Autodesk Knowledge Network | Autodesk Account | Product Feedback
0 Likes
Message 6 of 12

Anonymous
Not applicable

I'm trying to capture the contents of only the MTEXT items and have them persist when I open the file in Navisworks. From what I've seen, I don't think this is possible unless I put the contents into another property field. There may be a solution by not creating them using MTEXT, but I'm not creating the models. I'm using models that are given to me by other departments.

 

I am trying to make a Navisworks plugin that generates saved viewpoints over each individual room. Everything works fine, except I need the saved viewpoint names to be the room numbers. This isn't possible because Navisworks sees MTEXT as a model item and the "contents" property field of the MTEXT model item aren't loaded into Navisworks.

0 Likes
Message 7 of 12

Anonymous
Not applicable
Accepted solution

I've found a solution that works for me. I wrote a small Autocad Plugin that finds all MTEXT items and creates a hyperlink in each with the URL and Description both equal to the contents. Navisworks will import hyperlinks (if there is a description) from .dwg files, so instead of searching for the MTEXT contents in my navisworks plugin, I just search for the MTEXT URL. The code for the plugin is below.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;

[assembly: CommandClass(typeof(SaveContents.Class1))]

namespace SaveContents
{
    public class Class1
    {
        [CommandMethod("SaveCon")]
        public static void TestTextChange()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject
                    (SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);

                foreach (ObjectId id in btr)
                {
                    Entity currentEntity = tr.GetObject(id, OpenMode.ForWrite, false) as Entity;
                    if (currentEntity == null)
                    {
                        continue;
                    }
                    if (currentEntity.GetType() == typeof(MText))
                    {
                        HyperLink hyper = new HyperLink();
                        hyper.Name = ((MText)currentEntity).Contents;
                        hyper.Description = ((MText)currentEntity).Contents;
                        ((MText)currentEntity).Hyperlinks.Add(hyper);
                    }
                }
                tr.Commit();
            }
        }
    }
}
Message 8 of 12

Anonymous
Not applicable

Hi Austin

 

Would you mind sharing the plugin you created?? I am very interested in trying it out...

 

Regards

Paul

0 Likes
Message 9 of 12

Anonymous
Not applicable

Hi Paul,

 

Here is the plugin itself. Extract that to your "C:\Program Files\Autodesk\AutoCAD 2016\Plugins" folder (I'm using 2016 MEP version). Once you've done that, open the file you want to use and do a NETLOAD and select the SaveContents plugin from that directory. After that, just select all MTEXT items (or only the MTEXT you want to use) and run the command SAVECON. This will save the Text Contents field from each MTEXT item selected as a Hyperlink on it's parent MTEXT model item. Then, if you open the file in Navisworks, you can use these hyperlinks to find the text contents of each MTEXT programmatically. I usually use a script in Navisworks that eliminates the "/L" or "/P" from the MTEXT if it has multiple lines.

 

I hope it helps you! 

Message 10 of 12

Anonymous
Not applicable

That works great, thanks so much Austin!!  

 

Is there a way to use an objects layer to fill out the hyperlink?

 

Also do you know of a way to script Navisworks to change selected items Hyperlinks to Labels and wipe the 'Link to file or URL' field?

0 Likes
Message 11 of 12

Anonymous
Not applicable

Glad it could help somebody! 

 

To answer your first question, just turn on the "Layer Properties" window and select the model item that you want to edit. You should be able to manually edit the hyperlink from there. I think that's what you were asking me...

 

As for the second question, I'm sure there are ways to do both of those things but I haven't researched enough to know what they are. I would assume that they probably have to be done in AutoCad, seeing as how Navisworks isn't really designed for editing ModelItems. 

 

Anyway, I hope that helps. I'm not really an Autodesk expert, I'm definitely more of a coder first. I'm definitely not familiar with all of the Autodesk products and the functionalities of their APIs.

0 Likes
Message 12 of 12

Anonymous
Not applicable

No sorry for not being clear, I was wondering if your code could be changed to to fill out the hyperlinks of multiple object types to match the layer name the objects are on?

 

Regards

Paul

0 Likes