Author Topic: Xref and UCS  (Read 3462 times)

0 Members and 1 Guest are viewing this topic.

cadpro

  • Guest
Xref and UCS
« 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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Xref and UCS
« Reply #1 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 ?
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

cadpro

  • Guest
Re: Xref and UCS
« Reply #2 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.  :-(

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Xref and UCS
« Reply #3 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.

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

--> Donate to theSwamp<--

cadpro

  • Guest
Re: Xref and UCS
« Reply #4 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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Xref and UCS
« Reply #5 on: April 02, 2007, 06:40:06 AM »
No.
Tony seems to be giving you good advice ... I'll leave you with him.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Xref and UCS
« Reply #6 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.
Me

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6979
  • AKA Daniel
Re: Xref and UCS
« Reply #7 on: April 02, 2007, 10:01:13 AM »
<removed silly comment> Doh!
« Last Edit: April 02, 2007, 11:15:54 AM by Danielm103 »

TonyT

  • Guest
Re: Xref and UCS
« Reply #8 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

cadpro

  • Guest
Re: Xref and UCS
« Reply #9 on: April 10, 2007, 03:14:24 AM »
Please help! :-(

cadpro

  • Guest
Re: Xref and UCS
« Reply #10 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

Bryco

  • Water Moccasin
  • Posts: 1850
Re: Xref and UCS
« Reply #11 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.

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Xref and UCS
« Reply #12 on: April 11, 2007, 05:07:00 PM »
 :lmao:
Me

cadpro

  • Guest
Re: Xref and UCS
« Reply #13 on: April 12, 2007, 01:05:14 AM »
 :-( coz it's urgent!

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Xref and UCS
« Reply #14 on: April 12, 2007, 01:18:32 AM »
:-( coz it's urgent!

Then hire a professional.
Me