Subscribe to this thread
Home - General / All posts - Script/C# equivalent code...how to...
MAILP3 post(s)
#28-Feb-15 22:18

I am trying to do the same thing in c# as I have done in Manifold scripting (VBScript)

VBScript:

Sub Main

SET mapActiveDocument = Application.ActiveDocument

SET mapComponentSet = mapActiveDocument.ComponentSet

SET mapDrawing = mapComponentSet.Item("mapDrawing")

SET mapObjectSet = mapDrawing.ObjectSet

MSGBOX mapObjectSet.Count

End Sub

c#

Manifold.Interop.Application mapApplication;

Manifold.Interop.Document mapActiveDocument;

Manifold.Interop.ComponentSet mapActiveComponentSet;

Manifold.Interop.Drawing mapDrawing;

mapApplication = (Manifold.Interop.Application)maMAP.Application;

mapActiveDocument = (Manifold.Interop.Document)mapApplication.ActiveDocument;

mapActiveComponentSet = (Manifold.Interop.ComponentSet)mapActiveDocument.ComponentSet;

mapDrawing = (Manifold.Interop.Drawing)mapActiveComponentSet.ItemByName("mapDrawing");

Im stuck with the above...ie.I cannot convert type to drawing...int to drawing....if you can help, that would be great!

Thanks

tjhb
10,094 post(s)
#01-Mar-15 00:02

ComponentSet.ItemByName() returns an index (the integer your're seeing). You can use this index to get the corresponding member of the collection.

There's also an error in the 5th C# line above: use Context.Application to get the Application object.

using Manifold.Interop.Scripts;

class Script {

    static void Main() {

        Manifold.Interop.Application mapApplication;

        Manifold.Interop.Document mapActiveDocument;

        Manifold.Interop.ComponentSet mapActiveComponentSet;

        Manifold.Interop.Drawing mapDrawing;

        //

        mapApplication = Context.Application; // no cast required

        mapActiveDocument = (Manifold.Interop.Document) mapApplication.ActiveDocument;

        mapActiveComponentSet = mapActiveDocument.ComponentSet; // no cast required

        mapDrawing = (Manifold.Interop.Drawing) mapActiveComponentSet[mapActiveComponentSet.ItemByName("mapDrawing")];

        // ...

    }

}

tjhb
10,094 post(s)
#01-Mar-15 00:20

P.s. you can tell whether an explicit cast is required by looking through Manifold.Interop[.dll] and Manifold.Interop.Scripts[.dll] in the Object Browser in Visual Studio.

E.g. Application.ActiveDocument returns Object, so a cast to Document is required. Document.ComponentSet already returns ComponentSet, so no cast is necessary there.

MAILP3 post(s)
#01-Mar-15 00:42

Thanks for the quick reply I'll try it without the casts,it's not pretty but this is how I did it in Visual Studio/C#

Manifold.Interop.Application mapApplication;

Manifold.Interop.Document mapActiveDocument;

Manifold.Interop.ComponentSet mapActiveComponentSet;

Manifold.Interop.Drawing mapDrawing;

Manifold.Interop.ObjectSet mapObjectSet;

string strMapFilePath=@"c:\Users\Public\";

string strMapFileName = "Test.map";

string strMapComponentName="MapDrawing";

int intMapObjectSetCount=0;

mapApplication = maMAP.Application;

mapActiveDocument = (Manifold.Interop.Document)mapApplication.ActiveDocument;

mapActiveDocument.Open(strMapFilePath + strMapFileName, true, false);

mapActiveComponentSet = (Manifold.Interop.ComponentSet)mapActiveDocument.ComponentSet;

mapDrawing = (Manifold.Interop.Drawing)mapActiveComponentSet[strMapComponentName];

mapObjectSet = (Manifold.Interop.ObjectSet)mapDrawing.ObjectSet;

intMapObjectSetCount = mapObjectSet.Count;

TextBoxCount.Text = intMapObjectSetCount.ToString();

tjhb
10,094 post(s)
#01-Mar-15 00:59

(Sorry I should have picked up you were writing an external application, not translating a script to C#.)

Manifold User Community Use Agreement Copyright (C) 2007-2021 Manifold Software Limited. All rights reserved.