TheSwamp

Code Red => .NET => Topic started by: cadpro on April 02, 2007, 02:24:12 AM

Title: Xref and UCS
Post by: cadpro on April 02, 2007, 02:24:12 AM
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
Title: Re: Xref and UCS
Post by: Kerry on April 02, 2007, 03:09:22 AM
I was going to say that you could cover all the bases and ask at AUGI as well ... but I see that you have.   :-D


Have you done the Labs ?

Can you change the UCS ?

Can you change the Layer ?
Title: Re: Xref and UCS
Post by: cadpro on April 02, 2007, 03:46:31 AM
I have done some labs, but didn't try to change the UCS and Layers. Thought I will look into it after I've done with trapping the Command Event.  :-(
Title: Re: Xref and UCS
Post by: Kerry on April 02, 2007, 05:06:23 AM
I have done some labs, but didn't try to change the UCS and Layers. Thought I will look into it after I've done with trapping the Command Event.  :-(

Sorry, I thought my hint was pretty good  :|

If you do a couple more, you may find your answers.

 
Title: Re: Xref and UCS
Post by: cadpro on April 02, 2007, 05:38:06 AM
Please have a look at this code. It works, but only with the document that was active when the dll was loaded. What could be wrong?

Code: [Select]
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.ApplicationServices


Public Class UCS

    Implements Autodesk.AutoCAD.Runtime.IExtensionApplication

    Private Doc As Document

    Public Sub New()
        Doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        AddHandler Doc.CommandWillStart, AddressOf cmdWillStart
    End Sub

    Public Shared Sub cmdWillStart(ByVal o As Object, ByVal e As CommandEventArgs)
        Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor

        Try
            If e.GlobalCommandName = "XREF" Then
                MsgBox(e.GlobalCommandName)
            End If
        Catch ex As Exception
            ed.WriteMessage("Error in cmdWillStart: " + ex.Message)
        End Try
    End Sub
Title: Re: Xref and UCS
Post by: Kerry on April 02, 2007, 06:40:06 AM
No.
Tony seems to be giving you good advice ... I'll leave you with him.
Title: Re: Xref and UCS
Post by: Glenn R on April 02, 2007, 08:35:00 AM
Nicely put Kerry.
On a side note, Tony seems to be remarkable restrained with this one - I wouldn't be.
Title: Re: Xref and UCS
Post by: It's Alive! on April 02, 2007, 10:01:13 AM
<removed silly comment> Doh!
Title: Re: Xref and UCS
Post by: TonyT on April 04, 2007, 02:22:54 PM
Nicely put Kerry.
On a side note, Tony seems to be remarkable restrained with this one - I wouldn't be.

Well, I hope he can learn the difference
between the assignment and equal operators:

Code: [Select]
e.GlobalCommandName = "XREF" Then
Title: Re: Xref and UCS
Post by: cadpro on April 10, 2007, 03:14:24 AM
Please help! :-(
Title: Re: Xref and UCS
Post by: cadpro on April 11, 2007, 02:20:17 AM
Please can anyone help me to convert this code to vb.net?

Code: [Select]
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
Title: Re: Xref and UCS
Post by: Bryco on April 11, 2007, 09:43:59 AM
Don't you get a bit dizzy posting everywhere,
"Help,Help",post post ,"Help,help" post post.
Title: Re: Xref and UCS
Post by: Glenn R on April 11, 2007, 05:07:00 PM
 :lmao:
Title: Re: Xref and UCS
Post by: cadpro on April 12, 2007, 01:05:14 AM
 :-( coz it's urgent!
Title: Re: Xref and UCS
Post by: Glenn R on April 12, 2007, 01:18:32 AM
:-( coz it's urgent!

Then hire a professional.