I'm trying to adjust the properties of some block objects in Mspace. When the file contains external referances the function fails, when it has none it works perfectly.
Dim modelSpace As BlockTableRecord = DirectCast(M_trans.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead), BlockTableRecord)
For Each id As ObjectId In modelSpace
Dim ent As Autodesk.AutoCAD.DatabaseServices.Entity = DirectCast(M_trans.GetObject(id, OpenMode.ForWrite), Autodesk.AutoCAD.DatabaseServices.Entity)
ent.Color = Color.FromColorIndex(ColorMethod.ByLayer, 256)
Using the above to get all objectid's and filter through them then using:
If TypeOf ent Is BlockReference Then
Dim br As BlockReference = DirectCast(ent, BlockReference)
Dim btr As BlockTableRecord = DirectCast(M_trans.GetObject(br.BlockTableRecord, OpenMode.ForRead), BlockTableRecord)
If Not btr.IsFromExternalReference Then
It doesn't seem to be working, any ideas why?
Solved! Go to Solution.
Solved by MikeEvansUK. Go to Solution.
Hi,
I see you get Dim btr As BlockTableRecord in OpenMode.ForRead.
Do you call btr.UpgradeOpen() after that to make changes ?
Thanks,
Hi Partha, thanks I did notice that and changed it to Open.forwrite as I will be adjusting.
I seem to have some other issues but need to delve a bit deeper before I ask any more questions for School boy errors <Grin>
I have narrowed my issue down..
I am iterating through the layertable and am thawing / turning on and unlocking every layer then modifying the objects but i am getting an error that a layer is locked.
it would seem that if the current layer is locked it does not unlock it or ignores it and throws an error, if the current layer is not locked it does not have any issues and runs correctly. Is there a reason for this or is this a 2013 bug?
''code is
For Each ltid As ObjectId In lt
Try
acLyrTblRec = M_trans.GetObject(ltid, OpenMode.ForWrite)
acLyrTblRec.IsOff = False
acLyrTblRec.IsFrozen = False
acLyrTblRec.IsLocked = False
acLyrTblRec.Dispose()
Catch ex1 As System.Exception
ed.WriteMessage(("Exception: Ex1: " + ex1.Message))
End Try
Next
Mike
I did a quick test using Civil 3D 2013 and I find if the current layer is locked we can unlock it -
if (acLyrTblRec.IsLocked)
{
acLyrTblRec.IsLocked = false;
}
Does it happen in every DWG file or on a specific DWG file. To investigate it further can you create a simple DWG file with few layers and set the prop and try unlock / lock them using your code snippet ?
Thanks,
Partha.
Thanks for the help.
I added a new section of code to check through the layers and if current ensure it's unlocked, it didn't seem to work inside the code which just ran through the layers. Thereafter it worked.
Dim oLayer As LayerTableRecord = CType(M_trans.GetObject(db.Clayer, OpenMode.ForWrite), LayerTableRecord)
If (oLayer.IsOff) Then
oLayer.IsOff = False
End If
If (oLayer.IsFrozen) Then
oLayer.IsFrozen = False
End If
If (oLayer.IsLocked) Then
oLayer.IsLocked = False
End If
Next I had an issue with Paperspace & modelspace. It seemed that if I ran the code from Paperspace it wouldn't adjust or save the blocks. If run in modelspace it run correctly.
I had opened the blocktable but not in modelspace (does this make a difference?
I ended up checking for tilemode and switching to modelspace then it worked as expected.
Learned a lot here as this is the first pure .net code I have written, mostly before I was using managed wrapped .com.
Thanks again.
Mike
Mike -
I am glad to know that 🙂
Cheers,