.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with Polyline3Ds in BlockReference

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
hassanhafeez33
724 Views, 9 Replies

Problem with Polyline3Ds in BlockReference

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 🙂

 

 

9 REPLIES 9
Message 2 of 10

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.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 3 of 10

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 :S

Message 4 of 10


@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?

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 5 of 10

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.

Message 6 of 10


@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

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 7 of 10

Hi again, Alexander. 

 

Your solution regarding events works like a charm.  😄 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 😛 

 

 

Message 8 of 10

>> 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.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 9 of 10

Thanks Again, Alexander. 

 

But I wonder why its not implemented 😮

 

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

Message 10 of 10


@hassanhafeez33 wrote:

But I wonder why its not implemented 😮


What entities support a non-uniform scale matrix?

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost