Author Topic: change cross hair size  (Read 6754 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;
        }
    }
}