[Frage] Bug mit Polygonzug erweitern?

Schlagworte:
  • Python
  • Polygon

Hallo zusammen,

ich bin mir nicht sicher, ob hier ein Bug auftritt, oder ich das Problem bin:

Ich habe einen Polygonzug mit 3 Punkten:

poly1 = AllplanGeo.Polygon2D()
poly1 += AllplanGeo.Point2D( 0 , 0)
poly1 += AllplanGeo.Point2D( 20 , 0)
poly1 += AllplanGeo.Point2D( 20, 20)

jetzt will ich erstmal poly1 behalten und einen weiteren polygonzug mit punkten anhängen.

poly2 = poly1
poly2 += AllplanGeo.Point2D( -20, 20)
poly2 += AllplanGeo.Point2D( -20, 0)

jetzt aber poly1 in ein Element kreiere:
element = AllplanBasisElements.ModelElement2D(common_props, poly1)

wird mir die Geometrie vom erweiterte poly2 erstellt, statt vom poly1.

Habe ich einen Denkfehler, oder muss das so sein?

Hier mein exakter Code allerdings inkl. Variabeln:

betonlinefussunten = AllplanGeo.Polygon2D()
betonlinefussunten += AllplanGeo.Point2D( -900 , 0)
if bretteinlage == True:
betonlinefussunten += AllplanGeo.Point2D( 0 - bretteinlagelange / 2 , 0)
betonlinefussunten += AllplanGeo.Point2D( 0 - bretteinlagelange / 2 , 0 - bretteinlagedicke)
betonlinefussunten += AllplanGeo.Point2D( bretteinlagelange / 2 , 0 - bretteinlagedicke)
betonlinefussunten += AllplanGeo.Point2D( bretteinlagelange / 2 , 0 )
betonlinefussunten += AllplanGeo.Point2D( 900 , 0)

betonstilflacheunten = betonlinefussunten
betonstilflacheunten += AllplanGeo.Point2D( 900 , -300 )
betonstilflacheunten += AllplanGeo.Point2D( -900 , -300 )
betonstilflacheunten += AllplanGeo.Point2D( -900 , 0 )

betonstilflacheunten = AllplanGeo.Move(betonstilflacheunten, AllplanGeo.Vector2D(0, 1000))
betonlinefussunten = AllplanGeo.Move(betonlinefussunten, AllplanGeo.Vector2D(0, 1000))

betonlinefussuntenelement = AllplanBasisElements.ModelElement2D(common_props_outline, betonlinefussunten)

seitenansicht1.append(betonlinefussuntenelement) #<--- Liste für späteres PythonPart

Gruss Sebastian

Hallo Sebastian,

in Python wird bei poly2 = poly1 die Referenz auf poly1 übergeben. Damit wirken sich Änderungen in poly1 oder poly2 immer auf beide Objekte aus.

Wenn poly2 eine Kopie sein soll, dann musst Du

poly2 = AllplanGeo.Polygon2D(poly1)

verwenden.

Viele Grüße
Horst