- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
So basically, tale as old as time, I don't know if what did this was the fact I was getting an error every 5 minutes saying that my License had expired until I logged out and logged back in again, or the fact almost immediately after my cat walked across the keyboard but now all the sudden none of my scripts work. Some details I noticed are:
1. AutoCAD no longer asks me if I'm sure I want to load it or if I don't want to load it. I thought that was weird.
2. It still shows my copyright info in the editor pane, and it actually can do one single command for some reason and I suspect it has something to do with the line that says "<Assembly: CommandClass(GetType(VADEW.VADEWCommand))>" in my script.
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
<Assembly: CommandClass(GetType(VADEW.VADEWCommand))>
Namespace VADEW
Public Class VADEWCommand
Private Shared _displacement As Vector3d
<CommandMethod("VADEW")>
Public Sub MoveEntities()
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = acDoc.Editor
If _displacement.IsZeroLength Then
Dim pt1Res As PromptPointResult = ed.GetPoint("Select the first point: ")
If pt1Res.Status <> PromptStatus.OK Then Return
Dim pt2Res As PromptPointResult = ed.GetPoint("Select the second point: ")
If pt2Res.Status <> PromptStatus.OK Then Return
_displacement = pt2Res.Value - pt1Res.Value
Else
_displacement = -_displacement
End If
MoveModelSpaceEntities(acDoc.Database, _displacement)
ed.WriteMessage("Entities moved. Invoke VADEW again to move them back.")
End Sub
Private Sub MoveModelSpaceEntities(database As Database, displacement As Vector3d)
Using tr As Transaction = database.TransactionManager.StartTransaction()
Dim bt As BlockTable = tr.GetObject(database.BlockTableId, OpenMode.ForRead)
Dim btr As BlockTableRecord = tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
For Each objectId As ObjectId In btr
Dim entity As Entity = tr.GetObject(objectId, OpenMode.ForWrite)
entity.TransformBy(Matrix3d.Displacement(displacement))
Next
tr.Commit()
End Using
End Sub
End Class
End Namespace
Once again to be clear the above is an example of code that seems to work. But when I try to execute any other command like what's below, it just says the command doesn't exist:
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Runtime
Public Class TextJig
Inherits EntityJig
Private _position As Point3d
Public Sub New(entity As Entity, initialPosition As Point3d)
MyBase.New(entity)
_position = initialPosition
End Sub
Protected Overrides Function Sampler(prompts As JigPrompts) As SamplerStatus
Dim jigOpts As New JigPromptPointOptions("\nSpecify insertion point:")
jigOpts.BasePoint = _position
jigOpts.UseBasePoint = True
Dim res As PromptPointResult = prompts.AcquirePoint(jigOpts)
If res.Status = PromptStatus.OK Then
_position = res.Value
Return SamplerStatus.OK
Else
Return SamplerStatus.Cancel
End If
End Function
Protected Overrides Function Update() As Boolean
Dim text As MText = TryCast(Entity, MText)
If text IsNot Nothing Then
text.Location = _position
Return True
Else
Return False
End If
End Function
End Class
Public Class BeegTexto
' godzilla
<CommandMethod("GDZA")>
Public Sub CreateLargeText()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
' Step 1: Select a text object
Dim peo As New PromptEntityOptions("\nSelect a text object:")
peo.SetRejectMessage("Selected entity is not a text object.")
peo.AddAllowedClass(GetType(MText), True)
Dim per As PromptEntityResult = ed.GetEntity(peo)
If per.Status <> PromptStatus.OK Then
Return
End If
Using tr As Transaction = db.TransactionManager.StartTransaction()
' Step 2: Access the selected MText object and change its properties
Dim selectedText As MText = CType(tr.GetObject(per.ObjectId, OpenMode.ForRead), MText)
Dim newText As MText = CType(selectedText.Clone(), MText)
' Change layer
newText.Layer = "OHIO_ROAD_NAMES_LARGE"
' Change text height and line spacing
newText.TextHeight = 150
newText.LineSpacingFactor = 250 / newText.TextHeight
' Step 3: Use a jig to position the new large text object
Dim textJig As New TextJig(newText, newText.Location)
Dim res As PromptResult = ed.Drag(textJig)
If res.Status = PromptStatus.OK Then
' Add the new text object to the drawing
Dim btr As BlockTableRecord = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)
btr.AppendEntity(newText)
tr.AddNewlyCreatedDBObject(newText, True)
End If
' Step 4: Commit the transaction
tr.Commit()
End Using
End Sub
End Class
Any idea what might be going on here?
Solved! Go to Solution.