question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Displaying compounds

See original GitHub issue

Just experimenting with this really nice package and stumbled along this error when trying to show a compound

Wondering if here could be a special case for handling cadquery compounds in this section of the code as I don’t think they have a .val() attribute

trying the show() function with pip install jupyter-cadquery==2.0.0-rc1 and also tried adding pip install git+https://github.com/bernhard-42/cadquery-massembly

~/anaconda3/lib/python3.8/site-packages/jupyter_cadquery/cadquery/cad_objects.py in show(render_mates, mate_scale, *cad_objs, **kwargs)
    359     mate_scale = mate_scale or get_default("mate_scale")
    360 
--> 361     assembly = to_assembly(*cad_objs, render_mates=render_mates, mate_scale=mate_scale)
    362 
    363     if assembly is None:

~/anaconda3/lib/python3.8/site-packages/jupyter_cadquery/cadquery/cad_objects.py in to_assembly(render_mates, mate_scale, *cad_objs)
    310             assembly.add_list(_from_vector(cad_obj, obj_id))
    311 
--> 312         elif isinstance(cad_obj.val(), Vector):
    313             assembly.add_list(_from_vectorlist(cad_obj, obj_id))
    314 

AttributeError: 'Compound' object has no attribute 'val'

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
bernhard-42commented, Mar 8, 2021

@Shimwell Not that I understand anything of this, but it looks nice and I thought to share how you can build colored models with jupyter-cadquery. Maybe you knew that anyhow, but I was actually curious how it would look like, so I gave it a try 😉

parts = []

colors = {
    "Plasma": (153, 50, 204),
    "CenterColumnShieldCylinder": (0, 0, 139),
    "BlanketFP": (102, 205, 170),
    "RotateStraightShape": (139, 0, 0),
    "ToroidalFieldCoilCoatHanger": (0, 0, 139),
    "PoloidalFieldCoilSet": (139, 0, 0),
    "PoloidalFieldCoilCaseSetFC": (128, 128, 0)
}

for shape_or_compound in my_reactor.shapes_and_components:
    name = shape_or_compound.__class__.__name__
    if isinstance(
            shape_or_compound.solid,
            (cq.occ_impl.shapes.Shape, cq.occ_impl.shapes.Compound)):
        for i, solid in enumerate(shape_or_compound.solid.Solids()):
            parts.append(Part(solid, name=f"{name}{i}", color=colors[name]))
    else:
        parts.append(Part(shape_or_compound.solid.val(), name=f"{name}", color=colors[name]))

PartGroup(parts)

image

image

2reactions
shimwellcommented, Mar 9, 2021

This is perfect timing and we were just looking for a way to color the components, we have a growing collection of reactors and the manual coloring was really starting to add up.

bernhard-42 has just shown us the way

@RemDelaporteMathurin and @billingsley-john I vote we add default RGB colors to all the parametric components and then we can remake this without having to do it manually and perhaps some of the images in the docs can be automated as well

Read more comments on GitHub >

github_iconTop Results From Across the Web

5.3: Chemical Formulas - How to Represent Compounds
The empirical formula tells the lowest whole-number ratio of elements in a compound. The empirical formula does not show the actual number ...
Read more >
Molecules and compounds overview | Atomic structure (article)
A compound is a distinct group of atoms held together by chemical bonds. ... is that the order in which the atoms are...
Read more >
How to Draw Skeletal Structure or Bond-Line ... - YouTube
http://leah4sci.com/skeletal presents: How to Draw Skeletal Structures for Organic Compounds Watch Next: General Chemistry Review for ...
Read more >
Chemical Structures—Visualizing the Invisible
SF Table 2.2 shows four different models used for showing the molecule for ... In general, why are models important when studying elements...
Read more >
Compound Interest – Explorations of everyday chemical ...
Preview graphic for the fuels for spacecraft graphic in C&EN, showing a satellite and rockets. Rockets require a huge amount of energy to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found