.NET

Reply
Active Contributor
xdbk07
Posts: 42
Registered: ‎11-06-2012
Message 1 of 11 (295 Views)
Accepted Solution

eNotAplicable error

295 Views, 10 Replies
05-17-2013 03:08 AM

Hi All,

 

I met error "eNotAplicable" when I try to turn off object in viewports each. What happen?

 

Thanks,

Moderator
Alexander.Rivilis
Posts: 1,388
Registered: ‎04-09-2008
Message 2 of 11 (271 Views)

Re: eNotAplicable error

05-17-2013 09:31 AM in reply to: xdbk07

xdbk07 wrote:

Hi All,

 

I met error "eNotAplicable" when I try to turn off object in viewports each. What happen?

 

Thanks,


How you try to turn off object in viewports? Please provide your's code.


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

Active Contributor
xdbk07
Posts: 42
Registered: ‎11-06-2012
Message 3 of 11 (267 Views)

Re: eNotAplicable error

05-17-2013 09:57 AM in reply to: xdbk07

Thanks for help.

 

Here is the code:

    Public Sub OFFVIEWPORT()
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database
        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
            Dim lays As DBDictionary = acTrans.GetObject(acCurDb.LayoutDictionaryId, OpenMode.ForRead)
            For Each item As DBDictionaryEntry In lays
                If item.Key <> "Model" Then
                    Dim lay As Layout = TryCast(acTrans.GetObject(item.Value, OpenMode.ForRead, False, True), Layout)
                    For Each vpid As ObjectId In lay.GetViewports()
                        Dim vp As Autodesk.AutoCAD.DatabaseServices.Viewport = TryCast(acTrans.GetObject(vpid, OpenMode.ForWrite, True, True), Autodesk.AutoCAD.DatabaseServices.Viewport)

                        vp.On = False 'Error
                       'vp.on=true 'is OK
                    Next
                End If
            Next
            acTrans.Commit()
        End Using
    End Sub

 

*Expert Elite*
norman.yuan
Posts: 946
Registered: ‎04-27-2009
Message 4 of 11 (251 Views)

Re: eNotAplicable error

05-17-2013 02:08 PM in reply to: xdbk07

You may want to try the code like this:

 

    For Each vpid As ObjectId In lay.GetViewports()


            Dim vp As Autodesk.AutoCAD.DatabaseServices.Viewport = TryCast

 

           ''you cannot turn off viewport the layout itself is shown in it

           If vp.Number<>1 Then

              vp.On=False

          End If

 

    Next

Active Contributor
xdbk07
Posts: 42
Registered: ‎11-06-2012
Message 5 of 11 (242 Views)

Re: eNotAplicable error

05-18-2013 05:02 AM in reply to: norman.yuan

Hi,

 

I changed the code but it did not solve the proplem. An error occurred while processing your guidance. At "Model space" error is: "eNotAplicable" or at "layout" error is "Autocad application has stopped working".

 

Thanks,

*Expert Elite*
norman.yuan
Posts: 946
Registered: ‎04-27-2009
Message 6 of 11 (235 Views)

Re: eNotAplicable error

05-18-2013 06:13 AM in reply to: xdbk07

Well, I forgot to mention that if the layout is not active, all viewport's Number property would be -1 and you cannot turn it on or off. So, you need to set each layout as current before turn viewport on the layout on/off. Here is sample code that toggle viewports on one or more layouts on or off:

 

public class MyCommands 
{
    private static bool _vpOn = true;

    [CommandMethod("ToggleVP")]
    public static void RunToggleViewport()
    {
        _vpOn = !_vpOn;
        ToggleViewport(_vpOn);
    }

    private static void ToggleViewport(bool vpOn)
    {
        Document dwg = Application.DocumentManager.MdiActiveDocument;
        Editor ed = dwg.Editor;
        Database db = dwg.Database;

        LayoutManager lManager = LayoutManager.Current;
        string curLayout = lManager.CurrentLayout;

        try
        {
            using (Transaction tran = db.TransactionManager.StartTransaction())
            {
                DBDictionary layDic = (DBDictionary)tran.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
                foreach (DBDictionaryEntry entry in layDic)
                {
                    if (entry.Key.ToUpper() != "MODEL")
                    {
                        Layout layout = (Layout)tran.GetObject(entry.Value, OpenMode.ForRead);
                        lManager.CurrentLayout = layout.LayoutName;
                        ed.WriteMessage("\nLayout: {0}", layout.LayoutName);

                        ObjectIdCollection vpIds = layout.GetViewports();
                        foreach (ObjectId id in vpIds)
                        {
                            Viewport vp = (Viewport)tran.GetObject(id, OpenMode.ForRead);
                            ed.WriteMessage("\n =>Viewport number: {0}", vp.Number);
                            if (vp.Number != 1)
                            {
                                vp.UpgradeOpen();
                                vp.On = vpOn;
                            }
                        }
                    }
                }

                tran.Commit();
            }
        }
        finally
        {
            if (lManager.CurrentLayout != curLayout)
            {
                lManager.CurrentLayout = curLayout;
            }
        }
    }
}

 

Active Contributor
xdbk07
Posts: 42
Registered: ‎11-06-2012
Message 7 of 11 (202 Views)

Re: eNotAplicable error

05-20-2013 12:30 AM in reply to: norman.yuan

Thanks for help,

 

It's work but the progress is too slow. It's takes some minutes to turn off all viewports of about 10 layouts. I think because Acad regen after switch layout each. Please give me a suggestion.

 

Thanks,

*Expert Elite*
norman.yuan
Posts: 946
Registered: ‎04-27-2009
Message 8 of 11 (183 Views)

Re: eNotAplicable error

05-21-2013 06:33 AM in reply to: xdbk07

You may play around with "Layout Regen Options" ("Options" dialog box, tab "System"). Try select different radio button to run the code.

 

The 3 radion buttons are corresponding to the 3 values of system variable " LAYOUTREGENCTL" (0, 1, and 2). With the best result of your try, you can then set the system variable to the desired value before runnong your code to toggle viewports on layouts on and off, and then set the system variable back at the end of your code.

 

Active Contributor
ditran
Posts: 27
Registered: ‎01-28-2013
Message 9 of 11 (179 Views)

Re: eNotAplicable error

05-21-2013 08:14 AM in reply to: norman.yuan

Can you help me the code?

*Expert Elite*
norman.yuan
Posts: 946
Registered: ‎04-27-2009
Message 10 of 11 (162 Views)

Re: eNotAplicable error

05-21-2013 02:33 PM in reply to: ditran

What code you need help? Do you mean how to set system variable "LAYOUTREGNCTL"? Something like this:

 

//Save current value of the system variable

object oldValue=Application.GetSysVariable("LAYOUTREGENCTL");

 

//Set the system's variable to 0, 1, or 2, whichever is the best for the following operation

Application.SetSysVariable("LAYOUTREGENCTL", 0);

 

//Turn on/off viewport on layout, as discussed in previous posts

......

 

//Afterward, restore the system variable back to its original value

Application.SetSysVariable("LAYOUTREGENCTL", oldValue);

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community