Replies: 3 comments 2 replies
-
Some objects cannot be scaled non-uniformly, you may be able to explode all the objects in the block table record before creating the reference |
Beta Was this translation helpful? Give feedback.
0 replies
-
This isn't exactly what you're asking for, but it should help. Ask if you have any further problems from __future__ import annotations
import collections.abc as c
from pyrx import Db, Ge, command
class TempBlock:
def __init__(
self,
objs: c.Iterable[Db.Entity],
pos: Ge.Point3d = Ge.Point3d(0.0, 0.0, 0.0),
scale: Ge.Scale3d | None = None,
rotation: float | None = None,
db: Db.Database | None = None,
):
self._objs = tuple(objs)
self._pos = pos
self._scale = scale
self._rotation = rotation
self._db = db
self._btr_id: Db.ObjectId | None = None
def iter_objs(self):
for obj in self._objs:
if obj.isNullObj():
yield obj
else:
yield Db.Entity.cloneFrom(obj)
def create_btr(self) -> Db.BlockTableRecord:
btr = Db.BlockTableRecord()
objs = tuple(self.iter_objs())
btr.appendAcDbEntities(objs)
db = self._db or Db.workingDb()
bt = Db.BlockTable(db.blockTableId(), Db.OpenMode.kForWrite)
return bt.add(btr)
def create_bref(self) -> Db.BlockReference:
self._btr_id = self.create_btr()
bref = Db.BlockReference(self._pos, self._btr_id)
if self._scale is not None:
bref.setScaleFactors(self._scale)
if self._rotation is not None:
bref.setRotation(self._rotation)
return bref
def __enter__(self):
return self.create_bref()
def __exit__(self, exc_type, exc_value, traceback):
if self._btr_id is not None:
Db.BlockTableRecord(self._btr_id, Db.OpenMode.kForWrite).erase()
self._btr_id = None
def temp_block(
objs: c.Iterable[Db.Entity],
pos: Ge.Point3d = Ge.Point3d(0.0, 0.0, 0.0),
scale: Ge.Scale3d | None = None,
rotation: float | None = None,
db: Db.Database | None = None,
) -> TempBlock:
"""
Context manager to create a temporary block reference with the given objects.
"""
return TempBlock(objs, pos, scale, rotation, db)
@command
def doit():
circle = Db.Circle(Ge.Point3d(0, 0, 0), Ge.Vector3d(0, 0, 1), 5)
pline = Db.Polyline(
[
Ge.Point3d(0, 0, 0),
Ge.Point3d(5, 0, 0),
Ge.Point3d(5, 5, 0),
Ge.Point3d(0, 5, 0),
Ge.Point3d(0, 0, 0),
]
)
with temp_block(
[circle, pline],
pos=Ge.Point3d(10, 10, 0),
scale=Ge.Scale3d(-2, 1.5, 1),
rotation=0.5,
) as bref:
Db.curDb().addToModelspace(bref.explode()) |
Beta Was this translation helpful? Give feedback.
2 replies
-
Closing this in favor of #349 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Dear all,
I am trying to non-uniformly shape a blockref inserted. I have a defined a helper function as follows:
It is defined subsequently
It throws as follows
PyDb.ErrorStatusException: Exception!(eCannotScaleNonUniformly), function transformBy, Line 437, File PyDbEntity.cpp:
Hints on how to achieve the desired behaviour are kindly appreciated.
Best
Seb
Beta Was this translation helpful? Give feedback.
All reactions