TheSwamp
Code Red => .NET => Topic started 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
-
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 ?
-
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. :-(
-
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.
-
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?
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
-
No.
Tony seems to be giving you good advice ... I'll leave you with him.
-
Nicely put Kerry.
On a side note, Tony seems to be remarkable restrained with this one - I wouldn't be.
-
<removed silly comment> Doh!
-
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:
e.GlobalCommandName = "XREF" Then
-
Please help! :-(
-
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
-
Don't you get a bit dizzy posting everywhere,
"Help,Help",post post ,"Help,help" post post.
-
:lmao:
-
:-( coz it's urgent!
-
:-( coz it's urgent!
Then hire a professional.