AutoCAD crashes

AutoCAD crashes

Anonymous
Not applicable
1,402 Views
2 Replies
Message 1 of 3

AutoCAD crashes

Anonymous
Not applicable

Hey everyone,

 

I added this part to my perfectly working code, and for some reason now it crashes every time I want to run it. Can someone help me?

 

public sub
  
'add new layer
On Error Resume Next
    Dim Lay As AcadLayer
    Dim Color As AcadAcCmColor
    Set Color = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.22")
    Color.SetRGB 80, 100, 244
    
    Set Lay = ThisDrawing.Layers.Add("AnkersControle")
    With Lay
        .TrueColor = Color
        .Freeze = False
        .Lineweight = acLnWt009
    End With
On Error GoTo 0
    
'set new layer as current
ThisDrawing.SendCommand "_-layer _make PCLayer" & vbCr & vbCr
  
               
End Sub

 

0 Likes
Accepted solutions (1)
1,403 Views
2 Replies
Replies (2)
Message 2 of 3

grobnik
Collaborator
Collaborator
Accepted solution

Hi @Anonymous the procedure hangs on 

.TrueColor = Color

 Seems that the color application has some problems.

In order to set the TrueColor correct by cad versione I'm suggesting to apply

Dim color As AcadAcCmColor
    Set color = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor." & Left(CStr(AcadApplication.Version), 2))
    color.SetRGB 80, 100, 244

Le us know

0 Likes
Message 3 of 3

Anonymous
Not applicable

Hi again @grobnik !

 

Thank you very much for the speedy answer (again)!
It works perfectly!