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

Show and Hide Layers using C# .NET

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
Anonymous
2426 Views, 7 Replies

Show and Hide Layers using C# .NET

Hi All,

 

I am using Layers to show / hide the objects on my AutoCAD drawing.

I have created a windows Form and using that form i select what to show and hide, but the issue is that the drawing gets update when i close the Windows Form. I want the layers to show / hide as soon as i am clicking and button on the form and not when i close the form.

 

Please find the below code snippet where I am opening the form to show / hide the layers.

 

[CommandMethod("OnOff")]
public void OnOff()
{
USFView form = new USFView();
Autodesk.AutoCAD.ApplicationServices.Application.ShowModelessDialog(form);
}

 

In this form on the click of a radio button i am calling the On / Off event of the Layers.

 

 

Thanks in Advance!

7 REPLIES 7
Message 2 of 8
norman.yuan
in reply to: Anonymous

You need to show your code that actually does the layer showing/hiding work (I assume it is to turn layers on or off, or freeze/thaw layers), presumably in the form's code behind, which handles said radio button's CheckedChanged event.

 

BTW, you may or may not know, the way of showing a modeless form as your code does probably is not a good way to do it (creating a new instance of floating form in document context whenever the command is executed).

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 8
Anonymous
in reply to: norman.yuan

Hi Norman, Yuan,

 

 

I have even tried this way:

private void SetAutoCADFocus()
{
Process[] prcssArray = Process.GetProcessesByName("acad");
if (prcssArray.Length > 0)
SetForegroundWindow(prcssArray[0].MainWindowHandle);
}

but here also as soon as I am moving the focus out of the window it does the job. I hope you understand what i am asking here. Please find the attached image where I have the form opened in autocad, as soon as I click any of the radio buttons I want those layers to display in the drawing without even have to set Focus to autocad application.

 

 

Thanks In Advance!

Message 4 of 8
norman.yuan
in reply to: Anonymous

Well, again, you did not show the code that actually changes layer's On/Off property (the code obviously runs with your radio button's CheckChanged event handler.

 

This is likely solve you issue: after changing one or more layers' On/Off status, you y call Editor.UpdateScreen() of MdiActiveDocument.

 

Also, there is no need to search an "acad" process (your code runs inside AutoCAD, therefore there MUST BE at least 1 "acad" process. But there code be more than one, the the first one NAY NOT necessarily be the one user is working with) and calling WindowsAPI to set focus on AutoCAD window. If you use AutoCAD 2013 or later, you can simply set focus on AutoCAD window by:

 

Application.MainWindow.Focus();

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 5 of 8
antonio.leonardo
in reply to: Anonymous

Hi @Anonymous,

 

If you want to change this behavior:

 but the issue is that the drawing gets update when i close the Windows Form

 

Think about change you approach to be Out-Of-Process, decouple your "USFView form" to another assembly (an .exe or .dll application) and configure this isolated assembly to be a COM Interface, this will sending commands to your AutoCAD Application in Real Time, a good example to follow is this article here by Balaji Ramamoorthy.

 

 

Att,

Antonio Leonardo.

exam-483-programming-in-c.png

Message 6 of 8

Sorry, this is one of most possible strange solutions, technically which can do what the OP asked, suggested to a very minor issue in hand, which can be so easily solved with just one line of code as I suggested (Editor.UpdateScreen()).

 

Some issue can either be solved correctly and easily with a line or two code, or can be solved by going a huge detour with thousands of lines of code and complicated algorithms (implying how good/sophisticated we programmers are!). I do not see many would in favour the latter.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 7 of 8

@norman.yuan said:

Sorry, this is one of most possible strange solutions, technically which can do what the OP asked, suggested to a very minor issue in hand, which can be so easily solved with just one line of code as I suggested (Editor.UpdateScreen()).

It is absolutely agreed that certain coding solutions will be faster and simpler and will rise in the productivity quantifiers if one line of code is solved in comparison to the more laborious solution in a balance between gains and losses, but 'strange' is adjective that denotes little basements and low applicable in software development.

 

@norman.yuan said:

Some issue can either be solved correctly and easily with a line or two code, or can be solved by going a huge detour with thousands of lines of code and complicated algorithms (implying how good/sophisticated we programmers are!). I do not see many would in favour the latter.

A judgment to a developer whether it is 'good' and 'sophisticated' or 'not' at solving a strictly specific problem, just by choosing the approach, I disagree. Sincerely, this also denotes little basement in your words, however much your code with more advantages and gains. I have saw seniority ratings (Junior, Full, Senior, Leader) for HR+Tech assessments, which is based on the Developer experience and techinical proeficiency.

For you mention this, I believe you have not heard of a very old concept called function point analysis and the IFPUG. But, no problem, I will explain: IFPUG introduced the concept of software metrics worldwide, thanks to the IFPUG we had the first notions of gains and losses in the face of software choices.

The solutions shared above have approachs that will have your gains and your losses; one with more gains and more advantages and another with more losses; to the end user, will be indifferent.

I do not even know if there is 'sophistication' for programmers, but if it exists, it is much more closely associated with adopting good software architecture practices and adopting design patterns so that they are software capable of transmitting knowledge to software teams rather than have all the requirements of the stackholders as a priority.

 

Most importantly, especially if the program/software meets the requirements.

Message 8 of 8
kdub_nz
in reply to: Anonymous


@Anonymous wrote:

I want the layers to show / hide as soon as i am clicking and button on the form and not when i close the form.

In this form on the click of a radio button i am calling the On / Off event of the Layers.

 

Thanks in Advance!


Have a look here

http://www.theswamp.org/index.php?topic=55261.msg594936#msg594936

 

The proof of concept code uses Editor.UpdateScreen()  from the  control CheckedChanged event in a Modal Dialog.

Certainly simpler than some of the options mentioned.

 

Regards,

 


// Called Kerry in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect.

class keyThumper<T> : Lazy<T>;      another  Swamper

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