.NET

Reply
Contributor
hassanhafeez33
Posts: 17
Registered: ‎09-16-2011
Message 1 of 10 (250 Views)
Accepted Solution

Problem with Polyline3Ds in BlockReference

250 Views, 9 Replies
01-11-2013 10:18 AM

Hi All. 

 

I have a weird problem with exploding block reference with vb.net as follows.

 

When I use BR.explode(DBObjectCollection), and append the entities in the object collection to model space, 

the 3d Polylines inside the block reference do not get appended and I do not get any kind of error. The reason for this eludes me as of yet. (remember, simple polylines and lines and other objects do get appended to model space)

 

When I use BR.explodetoOwnerSpace(), the block reference explodes as it normally is expected to, but then I have no way to collect the objects from the exploded BR.

 

N.B, BR refers block reference. 

 

Thanks for any help in advance. 

 

I dont know whether any code is needed with this question but if it is, Ill attach it happily :smileyhappy:

 

 


hassanhafeez33 wrote:

...By sayin selection window, i mean that I did BR.explodetoOwnerSpace and then used ed.selectwindow to select the objects within the exisitin BR's extents...


Sorry but It's like the worst solution:

1) Editor.SelectWindow operate only with visible on screen (current viewport) entities.

2) Editor.SelectWindow can select many other entities.

3) etc.

You can use ObjectAppended events in order to get ObjectId's of all entities added to Database with explodetoOwnerSpace method:

Getting the entities created from ExplodeToOwnerSpace API

 

Moderator
Alexander.Rivilis
Posts: 1,449
Registered: ‎04-09-2008
Message 2 of 10 (241 Views)

Re: Problem with Polyline3Ds in BlockReference

01-11-2013 11:42 AM in reply to: hassanhafeez33

I've checked this code and it is work with 3DPolyline without problem:

 

[CommandMethod("ExplCurSpace")]
static public void ExplCurSpace()
{
  Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  Database db = Application.DocumentManager.MdiActiveDocument.Database;
  PromptEntityOptions opt = 
       new PromptEntityOptions("\nSelect a Block Reference: ");
  opt.SetRejectMessage("Not a Block Reference");
  opt.AddAllowedClass(typeof(BlockReference), true);
  PromptEntityResult rs = ed.GetEntity(opt);
  if (rs.Status == PromptStatus.OK) {
    using (Transaction tr = db.TransactionManager.StartTransaction()) {
      BlockTableRecord btrCur = 
           tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
      if (btrCur == null) return;
      BlockReference br = 
           tr.GetObject(rs.ObjectId, OpenMode.ForRead) as BlockReference;
      if (br == null) return;
      DBObjectCollection dbCol = new DBObjectCollection();
      br.Explode(dbCol);
      if (dbCol.Count > 0) {
        foreach (DBObject dbObj in dbCol) {
          Entity dbEnt = dbObj as Entity;
          if (dbEnt != null) {
            btrCur.AppendEntity(dbObj as Entity);
            tr.AddNewlyCreatedDBObject(dbObj, true);
          }
        }
        tr.Commit();
      }
    }
  }
}

 Try it.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Contributor
hassanhafeez33
Posts: 17
Registered: ‎09-16-2011
Message 3 of 10 (232 Views)

Re: Problem with Polyline3Ds in BlockReference

01-11-2013 12:42 PM in reply to: Alexander.Rivilis

Thanks Alexander For your quick reply. 

 

The problem is, I have tried it. and it doesnt seem to work for me. I have also tried casting every DbObject to Entity3D and appending it. But the code just seems to skip over the polyline3d.

 

One thing, Could it be related to the scenario if i were calling this funciton from another class with a main function? 

 

I do have implemented a workaround for the time being by using selection widnows but im not comfortable with them :smileyfrustrated:

Moderator
Alexander.Rivilis
Posts: 1,449
Registered: ‎04-09-2008
Message 4 of 10 (227 Views)

Re: Problem with Polyline3Ds in BlockReference

01-11-2013 01:17 PM in reply to: hassanhafeez33

hassanhafeez33 wrote:
...The problem is, I have tried it. and it doesnt seem to work for me. I have also tried casting every DbObject to Entity3D and appending it. But the code just seems to skip over the polyline3d...

Entity3d is geometrical class - e.g. class which can not be database resident and has not DBObject as parent class . It is the same that casting apple to pear.


hassanhafeez33 wrote:

...One thing, Could it be related to the scenario if i were calling this funciton from another class with a main function?


Maybe.


hassanhafeez33 wrote:

...I do have implemented a workaround for the time being by using selection widnows but im not comfortable with them...


Sorry, but I do not understand this idea at all.

First of all try my code as separate command. If this code is not work as expected then:
1) Attach small dwg-file with block which has Polyline3d

2) In which AutoCAD version you tested this code?


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Contributor
hassanhafeez33
Posts: 17
Registered: ‎09-16-2011
Message 5 of 10 (224 Views)

Re: Problem with Polyline3Ds in BlockReference

01-11-2013 01:22 PM in reply to: Alexander.Rivilis

Thanks again Alexander, 

 

Ill try it tomorrow, its past sleeping time here so i gotta go. Ill surely update if things progress.

 

By sayin selection window, i mean that I did BR.explodetoOwnerSpace and then used ed.selectwindow to select the objects within the exisitin BR's extents.

Moderator
Alexander.Rivilis
Posts: 1,449
Registered: ‎04-09-2008
Message 6 of 10 (222 Views)

Re: Problem with Polyline3Ds in BlockReference

01-11-2013 01:33 PM in reply to: hassanhafeez33

hassanhafeez33 wrote:

...By sayin selection window, i mean that I did BR.explodetoOwnerSpace and then used ed.selectwindow to select the objects within the exisitin BR's extents...


Sorry but It's like the worst solution:

1) Editor.SelectWindow operate only with visible on screen (current viewport) entities.

2) Editor.SelectWindow can select many other entities.

3) etc.

You can use ObjectAppended events in order to get ObjectId's of all entities added to Database with explodetoOwnerSpace method:

Getting the entities created from ExplodeToOwnerSpace API

 


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Contributor
hassanhafeez33
Posts: 17
Registered: ‎09-16-2011
Message 7 of 10 (198 Views)

Re: Problem with Polyline3Ds in BlockReference

01-12-2013 11:15 AM in reply to: Alexander.Rivilis

Hi again, Alexander. 

 

Your solution regarding events works like a charm.  :smileyvery-happy: nice one. Im just curious, does it effect performance overall? I assume it would. 

 

And realted to our original problem, I have worked out two reasons.

1. When a Block reference is scaled within a space, Your code and mine, do not seem to work with polylyine3ds. Whereas in an unscaled blockreference, your code and mine work perfectly.

 

2. When simple polylines are present in a block reference and it is scaled, the results seem strange. The polylines in the block reference seem to get exploded to lines directly. whereas polyline3ds do not appear at all.  (Tried both with your code, and mine; which are essentially the same)

 

Could you check if you can reproduce this on your own? 

 

Cheers. I know its a saturday but I dont have anything better to do :smileytongue: 

 

 

Moderator
Alexander.Rivilis
Posts: 1,449
Registered: ‎04-09-2008
Message 8 of 10 (189 Views)

Re: Problem with Polyline3Ds in BlockReference

01-12-2013 01:37 PM in reply to: hassanhafeez33

>> Im just curious, does it effect performance overall? I assume it would.

 

You can check it yourself but IMHO effect will be very small.

 

>>1. When a Block reference is scaled within a space, Your code and mine, do not seem to work with polylyine3ds.

>>Whereas in an unscaled blockreference, your code and mine work perfectly.

>>2. When simple polylines are present in a block reference and it is scaled, the results seem strange.

>>The polylines in the block reference seem to get exploded to lines directly. whereas polyline3ds do not appear at all.

>> (Tried both with >>your code, and mine; which are essentially the same)

 

If block has Polyline3d and scaled uniformly (e.g. Xscale == Yscale == Zscale) - block exploded  as expected, but if it scaled nonuniformly than:

12-01-2013 23-18-40.png

 

So with method Explode you can not explode nonuniformly scaled block with Polyline3d.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Contributor
hassanhafeez33
Posts: 17
Registered: ‎09-16-2011
Message 9 of 10 (185 Views)

Re: Problem with Polyline3Ds in BlockReference

01-12-2013 01:48 PM in reply to: Alexander.Rivilis

Thanks Again, Alexander. 

 

But I wonder why its not implemented :smileysurprised:

 

Anyways. I really appreciate your help :smileyhappy: keep up the good work!

Moderator
Alexander.Rivilis
Posts: 1,449
Registered: ‎04-09-2008
Message 10 of 10 (183 Views)

Re: Problem with Polyline3Ds in BlockReference

01-12-2013 01:51 PM in reply to: hassanhafeez33

hassanhafeez33 wrote:

But I wonder why its not implemented :smileysurprised:


What entities support a non-uniform scale matrix?


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!