Author Topic: change cross hair size  (Read 6749 times)

0 Members and 1 Guest are viewing this topic.

JONTHEPOPE

  • Guest
change cross hair size
« on: June 25, 2014, 03:28:28 PM »
I am using Autocad 2014 and I am trying to change the crosshair size using VS.
what is the best way to get to my end goal?
also my code has a red underline at void.
any help would be nice.

Code: [Select]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using System.Runtime.InteropServices;
 
[CommandMethod("PrefsSetCursor")]
public static void PrefsSetCursor()
{
 
    AcadPreferences acPrefComObj = (AcadPreferences)Application.Preferences;
    acPrefComObj.Display.CursorSize = 100;

}

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: change cross hair size
« Reply #1 on: June 25, 2014, 04:25:02 PM »
can you not just type
SETVAR
CURSORSIZE
100

Faster?
Be your Best


Michael Farrell
http://primeservicesglobal.com/

JONTHEPOPE

  • Guest
Re: change cross hair size
« Reply #2 on: June 25, 2014, 04:39:18 PM »
that is a easy solution, Thanks for the help.
 ^-^

Although I said I am changing the cursor size I still would like to access other options
through the Active x automation library so I can change other Autocad settings. 

I may have reached my limit.

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: change cross hair size
« Reply #3 on: June 25, 2014, 04:40:46 PM »
This worked for me.

Code - C#: [Select]
  1. [CommandMethod("PrefsSetCursor"]
  2. Public static void PrefsSetCursor()
  3. {
  4.     Application.SetSystemVariable("CursorSize", 100);
  5. }
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

JONTHEPOPE

  • Guest
Re: change cross hair size
« Reply #4 on: June 25, 2014, 05:26:51 PM »
I still seem to be missing somthing...

DO I need 
Code: [Select]
Autodesk.AutoCAD.Interop; this using  statement?

why does my using
Code: [Select]
Autodesk.AutoCAD.Interop; line have a red line under it?

(autocad 2014)

 

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: change cross hair size
« Reply #5 on: June 25, 2014, 05:51:36 PM »
SetSystemVariable is not a COM based method, it is defined in Autodesk.AutoCAD.ApplicationServices.Application

Perhaps try something like this :-

Code - C#: [Select]
  1. using AcadApp  = Autodesk.AutoCAD.ApplicationServices.Application;
  2.  
  3. /// then inside your app use:
  4.  
  5.         AcadApp.SetSystemVariable("CursorSize", 100);
  6.  

I find that this can avoid confusion for ex VB customisers regarding the source of methods.

I'd also recommend using an explicit naming convention for stuff defined in the interop assemblies.
Code - C#: [Select]
  1.     Autodesk.AutoCAD.Interop.AcadApplication objAcAppCOM;
  2.  
  3.     //// and ...
  4.  
  5.     AcadPreferences acPrefComObj = (AcadPreferences)Application.Preferences;
  6.  
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: change cross hair size
« Reply #6 on: June 25, 2014, 05:55:19 PM »
If you really must use COM .... this is directly from the help file . :

Code - C#: [Select]
  1. using Autodesk.AutoCAD.ApplicationServices;
  2. using Autodesk.AutoCAD.Runtime;
  3. using Autodesk.AutoCAD.Interop;
  4.  
  5. [CommandMethod("PrefsSetCursor")]
  6. public static void PrefsSetCursor()
  7. {
  8.     // This example sets the crosshairs for the drawing window
  9.     // to full screen.
  10.  
  11.     // Access the Preferences object
  12.     AcadPreferences acPrefComObj = (AcadPreferences)Application.Preferences;
  13.  
  14.     // Use the CursorSize property to set the size of the crosshairs
  15.     acPrefComObj.Display.CursorSize = 100;
  16. }
  17.  
  18.  

http://docs.autodesk.com/ACD/2014/ENU/files/GUID-7E1AC51A-CDD6-4CD5-8703-3D3A472BFFC5.htm


ADDED:
@JONTHEPOPE
Looks line used missed the include for the Interop assembly

Code - C#: [Select]
  1. using Autodesk.AutoCAD.Interop;
« Last Edit: June 25, 2014, 06:31:36 PM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: change cross hair size
« Reply #7 on: June 25, 2014, 06:21:42 PM »
SetSystemVariable is not a COM based method, it is defined in Autodesk.AutoCAD.ApplicationServices.Application


yup, forgot to add my using statements.  Thanks for the pickup Kerry.



Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: change cross hair size
« Reply #8 on: June 25, 2014, 06:40:07 PM »
< .... >

why does my using
Code: [Select]
Autodesk.AutoCAD.Interop; line have a red line under it?

(autocad 2014)

Have you added the references ??
This is from a test build. I used the downloaded SDK for development ( located on W:\ObjectARX 2014\..... )

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

JONTHEPOPE

  • Guest
Re: change cross hair size
« Reply #9 on: June 25, 2014, 08:13:12 PM »
ya, you guys are good!

Code: [Select]
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Interop;

[assembly: CommandClass(typeof(NEW_SET_PREFERENCES.Crosshairs))]

namespace NEW_SET_PREFERENCES
{
    public class Crosshairs
    {

        [CommandMethod("PrefsSetCursor")]
        public static void PrefsSetCursor()

        {   
            AcadPreferences acPrefComObj = (AcadPreferences)Application.Preferences;
            acPrefComObj.Display.CursorSize = 100;
        }
    }
}

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: change cross hair size
« Reply #10 on: June 26, 2014, 05:59:22 PM »
@JONTHEPOPE,
Just for completeness, for anyone following along later,  what was the cause of the problem.?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: change cross hair size
« Reply #11 on: June 26, 2014, 06:16:30 PM »
I would also like to ask why use a COM Method when there is a .net method that is more succint and much easier to use in my opinion.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Jeff H

  • Needs a day job
  • Posts: 6150
Re: change cross hair size
« Reply #12 on: June 26, 2014, 08:04:39 PM »
I have a side project that references COM APIs and use it to test calls and for intellisense, etc.....

Then I copy code into Main project and use DLR(dynamic) so do not have to worry about references.

JONTHEPOPE

  • Guest
Re: change cross hair size
« Reply #13 on: June 26, 2014, 10:18:29 PM »
My Problem was caused by me not knowing that I should load
two references into the solution explorer from the SDK.

Autodesk.AutoCAD.Interop
Autodesk.AutoCAD.Interop.Common

........................................................................................

Thanks Kerry

JONTHEPOPE

  • Guest
Re: change cross hair size
« Reply #14 on: June 26, 2014, 11:07:03 PM »
Good question why use COM instead of .NET.

The Help file told me that the AutoCAD.NET API didn't have any classes or methods to access the options through the AutoCAD Options dialog box.

Now I plan to try to access other tabs in the options dialogue box by changing a few keywords. 

I never expected to make it this far and I am well on my way to breaking my AutoCAD again.

Nice.

Code: [Select]
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Interop;

[assembly: CommandClass(typeof(NEW_SET_PREFERENCES.Crosshairs))]

namespace NEW_SET_PREFERENCES
{
    public class Crosshairs
    {

        [CommandMethod("PrefsSetCursor")]
        public static void PrefsSetCursor()

        {   
            AcadPreferences acPrefComObj = (AcadPreferences)Application.Preferences;
            acPrefComObj.Display.CursorSize = 100;
            acPrefComObj.Display.DisplayScrollBars = false;
        }
    }
}

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: change cross hair size
« Reply #15 on: June 27, 2014, 12:55:10 PM »
I know Jeff already mentioned this, but I suspect it needs to me stated more literally. 

We can remove the reference to the interop assembly by using System.dynamic:

Code - C#: [Select]
  1. using System;
  2. using Autodesk.AutoCAD.Runtime;
  3. using Autodesk.AutoCAD.ApplicationServices;
  4.  
  5. [assembly: CommandClass(typeof(NEW_SET_PREFERENCES.Crosshairs))]
  6.  
  7. namespace NEW_SET_PREFERENCES
  8. {
  9.     public class Crosshairs
  10.     {
  11.  
  12.         [CommandMethod("PrefsSetCursor")]
  13.         public static void PrefsSetCursor()
  14.  
  15.         {  
  16.             dynamic acPrefComObj = Application.Preferences;
  17.             acPrefComObj.Display.CursorSize = 100;
  18.             acPrefComObj.Display.DisplayScrollBars = false;
  19.         }
  20.     }
  21. }
« Last Edit: June 27, 2014, 12:58:19 PM by WILL HATCH »

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: change cross hair size
« Reply #16 on: June 27, 2014, 07:27:14 PM »
Thanks for the clarification Will.  I understand what Jeff said about using references in a side project so you can get intellisense, etc and then dynamic in the main project so you don't have to do the references but other than the references what is the advantage of using COM if you can get the same thing from .Net?
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: change cross hair size
« Reply #17 on: June 27, 2014, 08:25:40 PM »
Keith,
I think the 'advantage' or otherwise is not considered by most people.
A lot of people will be 'translating" vb/vba/VLisp code .. so COM is the natural option.
The use of .NET for accessing System variables requires a bit of research , ie "is there a variable for this property ??"
The Interop (using intellisense) is reasonably transparent regarding what is available .. there is a getter/setter for the property .. using .NET for system variables requires knowledge that the variable exists.

As JONTHEPOPE indicated, using COM is the only easily available way in some cases.

That being said, I do believe .NET is faster and more economical, when it is available.
I s'pose the argument could be made that if 'we' need to have COM available for some properties is it really such a dis-advantage to use it for properties that are available in the .NET API.

edit:fixed some fat finger stuff
« Last Edit: June 28, 2014, 12:34:40 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: change cross hair size
« Reply #18 on: June 30, 2014, 03:15:10 PM »
Thanks for the info Kerry.


I didnt consider that scenario mainly because I was only introduced to Cad and Autodesk products a few years ago and never got involved in VBA or com.  It was always .net for me.


A question that I have is that if Autodesk is requesting that VBA projects be updated to .net solutions.  IF and that is probably a big if, but if VBA goes away in the future would COM go with it?  So any updating that is done with COM would have to be done again?  So i guess the question is if VBA is a product of COM or is COM a product of VBA or are they just two separate items that are not linked?
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: change cross hair size
« Reply #19 on: June 30, 2014, 05:39:35 PM »
Hi Keith.

COM is independent of VBA, but is used by VBA and VB.
Com is also used by Visual Lisp, (Active-X).
I imagine it has a role in the new js API, but not sure.



kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

JONTHEPOPE

  • Guest
Re: change cross hair size
« Reply #20 on: July 07, 2014, 02:51:45 PM »
So I added more lines in but I don't know if this is the best way to do it? is there a way That I am suppose to save the changes to the BlockTable record?

Code: [Select]
            dynamic acPrefComObj = Application.Preferences;
            acPrefComObj.Display.CursorSize = 100;
            acPrefComObj.Display.DisplayScrollBars = false;
            acPrefComObj.Files.QNewTemplateFile = ("C:/Users/dgladeau/AppData/Local/Autodesk/AutoCAD 2014/R19.1/enu/Template/9999 Wanye Gretzky");
            acPrefComObj.Files.AutoSavePath = ("C:/AcadTemp");
            acPrefComObj.System.EnableStartupDialog = false;

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: change cross hair size
« Reply #21 on: July 07, 2014, 11:08:36 PM »
So I added more lines in but I don't know if this is the best way to do it? is there a way That I am suppose to save the changes to the BlockTable record?

< .. >

What changes are you making to a BlockTable record ??

Exactly what are you trying to do ?

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

JONTHEPOPE

  • Guest
Re: change cross hair size
« Reply #22 on: July 08, 2014, 12:49:23 AM »
Hi Kerry,

I'm not sure what I'm doing.
I put in a line for open and save but when I came back to work the next day my Qnew template setting was set to none.
I guess that I might need to apply my changes somehow so that the settings will stay changed, is this assumption right?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: change cross hair size
« Reply #23 on: July 08, 2014, 02:01:12 AM »
I don't have time to play with this at the moment.

I've never seen the need to do this sort of thing so I don't have experience with the issues you are having.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: change cross hair size
« Reply #24 on: July 08, 2014, 05:28:54 AM »
So I added more lines in but I don't know if this is the best way to do it? is there a way That I am suppose to save the changes to the BlockTable record?

Code: [Select]
            dynamic acPrefComObj = Application.Preferences;
            acPrefComObj.Display.CursorSize = 100;
            acPrefComObj.Display.DisplayScrollBars = false;
            acPrefComObj.Files.QNewTemplateFile = ("C:/Users/dgladeau/AppData/Local/Autodesk/AutoCAD 2014/R19.1/enu/Template/9999 Wanye Gretzky");
            acPrefComObj.Files.AutoSavePath = ("C:/AcadTemp");
            acPrefComObj.System.EnableStartupDialog = false;

Hi Kerry,

I'm not sure what I'm doing.
I put in a line for open and save but when I came back to work the next day my Qnew template setting was set to none.
I guess that I might need to apply my changes somehow so that the settings will stay changed, is this assumption right?

C:/Users/dgladeau/AppData/Local/Autodesk/AutoCAD 2014/R19.1/enu/Template/9999 Wanye Gretzky
Is not a valid template file.
The Preferences Files paths basically require string that is a valid folder path,  file path, or a for multiple values takes a string delimited  by ";".



Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: change cross hair size
« Reply #25 on: July 08, 2014, 06:32:35 AM »
... and, I just noticed : why are the strings in parenthesis ?

Jeff. The file string may be valid if the 9999 Wanye Gretzky is a .dwg or .dwt file.


Works for me ..

Code - C#: [Select]
  1.  
  2.             AcadPreferences acPrefComObj = (AcadPreferences) Application.Preferences;
  3.  
  4.             string templateFilePath = "c:/templates/Test space/cat - copy";  // <-- not on the safe list
  5.             acPrefComObj.Files.QNewTemplateFile = templateFilePath;
  6.  
  7.  
« Last Edit: July 08, 2014, 06:38:33 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: change cross hair size
« Reply #26 on: July 08, 2014, 07:14:48 AM »
... and, I just noticed : why are the strings in parenthesis ?

Jeff. The file string may be valid if the 9999 Wanye Gretzky is a .dwg or .dwt file.


Works for me ..

Code - C#: [Select]
  1.  
  2.             AcadPreferences acPrefComObj = (AcadPreferences) Application.Preferences;
  3.  
  4.             string templateFilePath = "c:/templates/Test space/cat - copy";  // <-- not on the safe list
  5.             acPrefComObj.Files.QNewTemplateFile = templateFilePath;
  6.  
  7.  
Ahhh,
assumed like a arse it had to have extension included and completely overlooked the  parenthesis.
Sorry about that, and thanks Kerry I could have wasted the pope's time.

JONTHEPOPE

  • Guest
Re: change cross hair size
« Reply #27 on: July 09, 2014, 02:02:17 PM »
Guys,

All my time is devoted to this site, the cult of hockey, and blu-ray discs.

I will never learn if I never fail.

Thanks again.