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

eNotAplicable error

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
ditran7577
1030 Views, 10 Replies

eNotAplicable error

Hi All,

 

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

 

Thanks,

10 REPLIES 10
Message 2 of 11


@ditran7577 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.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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 3 of 11
ditran7577
in reply to: ditran7577

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

 

Message 4 of 11
norman.yuan
in reply to: ditran7577

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

Message 5 of 11
ditran7577
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,

Message 6 of 11
norman.yuan
in reply to: ditran7577

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;
            }
        }
    }
}

 

Message 7 of 11
ditran7577
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,

Message 8 of 11
norman.yuan
in reply to: ditran7577

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.

 

Message 9 of 11
ditran
in reply to: norman.yuan

Can you help me the code?

Message 10 of 11
norman.yuan
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);

Message 11 of 11
ditran7577
in reply to: norman.yuan

Thanks for help. The process is not faster. I don'n know what happen?

Is there any way to turn off viewport each that we do not set the current layout to active layout?

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