Results 1 to 3 of 3

Thread: Change the UCS and Layer when the user types XREF in the command line

  1. #1
    Member
    Join Date
    2006-02
    Posts
    39
    Login to Give a bone
    0

    Default Change the UCS and Layer when the user types XREF in the command line

    Hi,

    I'm new to .NET. I had been trying to create a dll to change the UCS and Layer when the user types XREF in the command line. I don't know how to go about it. I just tried the code below, but it is not working. Can anybody help me?

    Imports System
    Imports System.Runtime.InteropServices
    Imports Autodesk.AutoCAD.Runtime
    Imports Autodesk.AutoCAD.ApplicationServices

    Imports acadApp = Autodesk.AutoCAD.ApplicationServices.Application

    Public Class UCS
    Public Sub XrefCommand()
    If acadApp.DocumentManager.MdiActiveDocument.CommandInProgress = "XREF" Then
    MsgBox("Done!")
    End If
    End Sub
    End Class

    Thanks

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,420
    Login to Give a bone
    0

    Default Re: Change the UCS and Layer when the user types XREF in the command line

    A command will only run once. You need to write code to respond to system events that will get executed each time the event occurs. That goes for any language, not just .NET.
    C:> ED WORKING....


    LinkedIn

  3. #3
    Member
    Join Date
    2006-02
    Posts
    39
    Login to Give a bone
    0

    Default Re: Change the UCS and Layer when the user types XREF in the command line

    Please can anyone help me to convert this code to vb.net?

    Option Explicit
    Dim CurUCS As AcadUCS
    Dim CurLayer As AcadLayer
    Dim UCSs As Object

    Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)

    If CommandName = "XREF" Or CommandName = "XATTACH" Then
    Set CurUCS = ThisDrawing.ActiveUCS
    Set CurLayer = ThisDrawing.ActiveLayer
    Call ShowWCS
    ThisDrawing.Layers("0").Freeze = False
    ThisDrawing.Layers("0").LayerOn = True
    ThisDrawing.ActiveLayer = ThisDrawing.Layers("0")
    End If

    End Sub
    Sub ShowWCS()
    '
    ' Display WCS
    '
    Dim wcs As Object
    Dim dorigin(0 To 2) As Double
    Dim dxAxisPnt(0 To 2) As Double
    Dim dyAxisPnt(0 To 2) As Double

    dorigin(0) = 0#
    dorigin(1) = 0#
    dorigin(2) = 0#

    dxAxisPnt(0) = 1#
    dxAxisPnt(1) = 0#
    dxAxisPnt(2) = 0#

    dyAxisPnt(0) = 0#
    dyAxisPnt(1) = 1#
    dyAxisPnt(2) = 0#

    Set wcs = ThisDrawing.UserCoordinateSystems.Add(dorigin, dxAxisPnt, dyAxisPnt, "WORLD")

    ' Display WCS.
    ThisDrawing.ActiveUCS = wcs
    End Sub

    Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
    If CommandName = "XREF" Or CommandName = "XATTACH" Then
    ThisDrawing.ActiveUCS = CurUCS
    ThisDrawing.ActiveLayer = CurLayer
    ThisDrawing.UserCoordinateSystems.Item("World").Delete
    End If

    End Sub

    Thanks

Similar Threads

  1. Xref layer color change
    By jsnow in forum AutoCAD General
    Replies: 8
    Last Post: 2009-03-05, 10:16 AM
  2. Replies: 4
    Last Post: 2007-06-08, 07:28 AM
  3. Replies: 6
    Last Post: 2007-05-30, 05:45 PM
  4. Replies: 10
    Last Post: 2007-04-27, 06:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •