Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

BlockReferance.isexternal function.

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
MikeEvansUK
474 Views, 6 Replies

BlockReferance.isexternal function.

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?

Mike Evans

Civil3D 2022 English
Windows 7 Professional 64-bit
Intel(R) Core(TM) i7-3820 CPU @ 3.60GHz (8 CPUs), ~4.0GHz With 32768MB RAM, AMD FirePro V4900, Dedicated Memory: 984 MB, Shared Memory: 814 MB

6 REPLIES 6
Message 2 of 7
Partha.Sarkar
in reply to: MikeEvansUK

Hi,

 

I see you get Dim btr As BlockTableRecord in OpenMode.ForRead.

 

Do you call btr.UpgradeOpen() after that to make changes ?

 

Thanks,



Partha Sarkar
Developer Technical Services
Autodesk Developer Network

Message 3 of 7
MikeEvansUK
in reply to: Partha.Sarkar

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>

 

Mike Evans

Civil3D 2022 English
Windows 7 Professional 64-bit
Intel(R) Core(TM) i7-3820 CPU @ 3.60GHz (8 CPUs), ~4.0GHz With 32768MB RAM, AMD FirePro V4900, Dedicated Memory: 984 MB, Shared Memory: 814 MB

Message 4 of 7
MikeEvansUK
in reply to: MikeEvansUK

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

Mike Evans

Civil3D 2022 English
Windows 7 Professional 64-bit
Intel(R) Core(TM) i7-3820 CPU @ 3.60GHz (8 CPUs), ~4.0GHz With 32768MB RAM, AMD FirePro V4900, Dedicated Memory: 984 MB, Shared Memory: 814 MB

Message 5 of 7
Partha.Sarkar
in reply to: MikeEvansUK

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 Sarkar
Developer Technical Services
Autodesk Developer Network

Message 6 of 7
MikeEvansUK
in reply to: MikeEvansUK

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 Evans

Civil3D 2022 English
Windows 7 Professional 64-bit
Intel(R) Core(TM) i7-3820 CPU @ 3.60GHz (8 CPUs), ~4.0GHz With 32768MB RAM, AMD FirePro V4900, Dedicated Memory: 984 MB, Shared Memory: 814 MB

Message 7 of 7
Partha.Sarkar
in reply to: MikeEvansUK

Mike -

 

I am glad to know that 🙂

 

Cheers,

 



Partha Sarkar
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report